Fixed issues with deepClone, built everything
This commit is contained in:
3002
test/_30s.js
3002
test/_30s.js
File diff suppressed because it is too large
Load Diff
@ -4,24 +4,33 @@ const {deepClone} = require('./_30s.js');
|
||||
test('deepClone is a Function', () => {
|
||||
expect(deepClone).toBeInstanceOf(Function);
|
||||
});
|
||||
const a = { foo: 'bar', obj: { a: 1, b: 2 } };
|
||||
const b = deepClone(a);
|
||||
const c = [{ foo: 'bar' }];
|
||||
const d = deepClone(c);
|
||||
const e = { edge: [] };
|
||||
const f = deepClone(e);
|
||||
const data = {
|
||||
a: [],
|
||||
b: [1, 2, 3],
|
||||
c: [{ foo: 'bar' }],
|
||||
d: {},
|
||||
e: { a: 'a', b: 'b', c: 'c', d: ['a', 'b', 'c'] },
|
||||
f: 1,
|
||||
g: true
|
||||
};
|
||||
const dupe = deepClone(data);
|
||||
test('Shallow cloning works', () => {
|
||||
expect(a).not.toBe(b);
|
||||
});
|
||||
test('Deep cloning works', () => {
|
||||
expect(a.obj).not.toBe(b.obj);
|
||||
});
|
||||
test('Array shallow cloning works', () => {
|
||||
expect(c).not.toBe(d);
|
||||
});
|
||||
test('Array deep cloning works', () => {
|
||||
expect(c[0]).not.toBe(d[0]);
|
||||
expect(data).not.toBe(dupe);
|
||||
});
|
||||
test('Array shallow cloning edge case works', () => {
|
||||
expect(f.edge).toEqual([]);
|
||||
expect(dupe.a).toEqual([]);
|
||||
});
|
||||
test('Array shallow cloning works', () => {
|
||||
expect(data.b).not.toBe(dupe.b);
|
||||
});
|
||||
test('Array deep cloning works', () => {
|
||||
expect(data.c[0]).not.toBe(dupe.c[0]);
|
||||
});
|
||||
test('Deep cloning works', () => {
|
||||
expect(data.d).not.toBe(dupe.d);
|
||||
expect(data.e).not.toBe(dupe.e);
|
||||
});
|
||||
test('Cloning primitives works', () => {
|
||||
expect(data.f).toBe(dupe.f);
|
||||
expect(data.g).toBe(dupe.g);
|
||||
});
|
||||
Reference in New Issue
Block a user