Skip to content

Commit 39ed05e

Browse files
committed
test(json-walk): 💍 add more walk() tests
1 parent 0ecf46f commit 39ed05e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/json-walk/__tests__/index.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,36 @@ test('can walk through a value', () => {
2626
3,
2727
]);
2828
});
29+
30+
test('can walk through null', () => {
31+
const value = null;
32+
const nodes: unknown[] = [];
33+
walk(value, (node) => {
34+
nodes.push(node);
35+
});
36+
expect(nodes).toEqual([
37+
null,
38+
]);
39+
});
40+
41+
test('can walk empty object', () => {
42+
const value = {};
43+
const nodes: unknown[] = [];
44+
walk(value, (node) => {
45+
nodes.push(node);
46+
});
47+
expect(nodes).toEqual([
48+
{},
49+
]);
50+
});
51+
52+
test('can walk empty array', () => {
53+
const value: any[] = [];
54+
const nodes: unknown[] = [];
55+
walk(value, (node) => {
56+
nodes.push(node);
57+
});
58+
expect(nodes).toEqual([
59+
[],
60+
]);
61+
});

0 commit comments

Comments
 (0)