-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
59 lines (55 loc) · 1.1 KB
/
Copy pathtest.js
File metadata and controls
59 lines (55 loc) · 1.1 KB
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
59
let check = require('./index');
// circular reference
let caseObj1 = {
a: 1,
b: {
b1: 1,
}
};
caseObj1.b.b2 = caseObj1;
caseObj1.c = caseObj1.b;
test('caseObj1', () => {
expect(check(caseObj1)).toStrictEqual(['.b.b2','.c']);
});
// This is not circular reference
let person = {name: 'Shawn You'}
let caseObj2 = {
a: person,
b: person,
}
test('caseObj2', () => {
expect(check(caseObj2)).toStrictEqual([]);
});
// This for test array
let menu = [
{
label: 'Home',
children: [
{
label: 'Product'
}
],
},
{
label: 'About',
extend: {}
}
];
menu[0].children[0].parent = menu[0];
menu[1].extend.home = menu[0].children[0];
test('Array test', () => {
expect(check(menu)).toStrictEqual(['[0].children[0].parent', '[1].extend.home']);
});
// object -> array
let family = {
name: 'Shawn You',
child: [
{
name: 'No',
}
]
}
family.child[0].parent = family;
test('Object contains array', () => {
expect(check(family)).toStrictEqual(['.child[0].parent']);
});