Skip to content

Commit 8b5212c

Browse files
Add test for not existing parentId
1 parent aecee0c commit 8b5212c

File tree

3 files changed

+84
-23
lines changed

3 files changed

+84
-23
lines changed

build/arrayToTree.spec.js

Lines changed: 38 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/arrayToTree.spec.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/arrayToTree.spec.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ describe('arrayToTree', () => {
1010
{ id: '1', parentId: '418', custom: 'ZZZz' },
1111
{ id: '418', parentId: null, custom: 'ü' },
1212
])).to.deep.equal([
13-
{ data: { id: '4', parentId: null, custom: 'abc' }, children: [
14-
{ data: { id: '31', parentId: '4', custom: '12' }, children: [] },
15-
] },
16-
{ data: { id: '418', parentId: null, custom: 'ü' }, children: [
17-
{ data: { id: '1941', parentId: '418', custom: 'de' }, children: [] },
18-
{ data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] },
19-
] },
13+
{
14+
data: { id: '4', parentId: null, custom: 'abc' }, children: [
15+
{ data: { id: '31', parentId: '4', custom: '12' }, children: [] },
16+
],
17+
},
18+
{
19+
data: { id: '418', parentId: null, custom: 'ü' }, children: [
20+
{ data: { id: '1941', parentId: '418', custom: 'de' }, children: [] },
21+
{ data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] },
22+
],
23+
},
2024
])
2125
})
2226

@@ -31,13 +35,40 @@ describe('arrayToTree', () => {
3135
] as any),
3236
{ id: 'num', parentId: 'ref' },
3337
)).to.deep.equal([
34-
{ data: { num: '4', ref: null, custom: 'abc' }, children: [
35-
{ data: { num: '31', ref: '4', custom: '12' }, children: [] },
36-
] },
37-
{ data: { num: '418', ref: null, custom: 'ü' }, children: [
38-
{ data: { num: '1941', ref: '418', custom: 'de' }, children: [] },
39-
{ data: { num: '1', ref: '418', custom: 'ZZZz' }, children: [] },
40-
] },
38+
{
39+
data: { num: '4', ref: null, custom: 'abc' }, children: [
40+
{ data: { num: '31', ref: '4', custom: '12' }, children: [] },
41+
],
42+
},
43+
{
44+
data: { num: '418', ref: null, custom: 'ü' }, children: [
45+
{ data: { num: '1941', ref: '418', custom: 'de' }, children: [] },
46+
{ data: { num: '1', ref: '418', custom: 'ZZZz' }, children: [] },
47+
],
48+
},
49+
])
50+
})
51+
52+
it('should ignore objects if parentId does not exist', () => {
53+
expect(arrayToTree([
54+
{ id: '4', parentId: null, custom: 'abc' },
55+
{ id: '31', parentId: '4', custom: '12' },
56+
{ id: '1941', parentId: '418', custom: 'de' },
57+
{ id: '1', parentId: '418', custom: 'ZZZz' },
58+
{ id: '418', parentId: null, custom: 'ü' },
59+
{ id: '1313', parentId: '13', custom: 'Not existing' },
60+
])).to.deep.equal([
61+
{
62+
data: { id: '4', parentId: null, custom: 'abc' }, children: [
63+
{ data: { id: '31', parentId: '4', custom: '12' }, children: [] },
64+
],
65+
},
66+
{
67+
data: { id: '418', parentId: null, custom: 'ü' }, children: [
68+
{ data: { id: '1941', parentId: '418', custom: 'de' }, children: [] },
69+
{ data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] },
70+
],
71+
},
4172
])
4273
})
4374

0 commit comments

Comments
 (0)