-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
58 lines (49 loc) · 1.37 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const deepClone = require('.');
describe('TEST: Testing deepClone function', () => {
test('Test: Deep Copy(first level)', () => {
const person = { name: 'Jon' };
expect(Object.is(deepClone(person), person)).toBe(false);
});
test('deepCopy nested (one level deep)', () => {
const person = { name: 'Jon', addr: { home: 'Winterfell' } };
expect(Object.is(deepClone(person.addr), person.addr)).toBe(false);
});
test('deepCopy deeply nested', () => {
const person = {
name: 'Jon',
addr: {
family: {
biological: {
name: 'Targaryen',
sigil: 'Three Red Dragon',
},
},
},
};
expect(
Object.is(
deepClone(person.addr.family.biological),
person.addr.family.biological
)
).toBe(false);
});
// huge arr
test('Array of 10 million+ items', () => {
const hugeArr = Array(10_000_000).fill('🔥');
hugeArr[3000] = Array(3000).fill({ randNumber: Math.random() });
expect(Object.is(deepClone(hugeArr)[3000], hugeArr[3000])).toBe(false);
});
// binaries
test('Object Containing Binaries', () => {
const bin = require('fs').readFileSync('index.spec.js', {
encoding: 'binary',
});
const obj = {
name: 'JavaScript',
desc: {
bin,
},
};
expect(Object.is(deepClone(obj), obj)).toBe(false);
});
});