Fixed issues with deepClone, built everything

This commit is contained in:
Angelos Chalaris
2019-01-12 11:42:14 +02:00
parent 4f1974cfd5
commit ac3223405b
16 changed files with 4816 additions and 4798 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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);
});