-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
53 lines (48 loc) · 1.22 KB
/
index.test.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
const jsonPath = require("./");
const assert = require("node:assert");
const { test } = require("node:test");
test("undefined set", () => {
const val1 = { locks: undefined, replicas: ["dev"] };
const val2 = jsonPath.set(
val1,
undefined,
{ locks: undefined, replicas: ["dev"], error: undefined },
false,
);
assert.deepStrictEqual(val2, { replicas: ["dev"] });
});
test("undefined set2", () => {
const val1 = {};
const val2 = jsonPath.set(
val1,
undefined,
{ locks: undefined, replicas: ["dev"], error: undefined },
false,
);
assert.deepStrictEqual(val2, { replicas: ["dev"] });
});
test("undefined set3", () => {
const val1 = { replicas: ["dev1"] };
const val2 = jsonPath.set(
val1,
null,
{ replicas: ["dev1"], locks: undefined },
false,
);
assert.equal(val1, val2);
});
test("undefined set4", () => {
const val1 = { replicas: ["dev1"] };
const val2 = jsonPath.set(
val1,
null,
{ locks: undefined, replicas: ["dev1"], error: undefined },
false,
);
assert.equal(val1, val2);
});
test("bad array index", () => {
const val1 = [1, 2, 3, undefined];
const val2 = jsonPath.set(val1, "foo[2]", 4, false);
assert.equal(val2, [1, 2, 3, null]);
});