-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathbasic.js
74 lines (69 loc) · 1.47 KB
/
basic.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import test from "node:test";
import assert from "node:assert";
import diff from "../dist/index.js";
test("new raw value", () => {
assert.deepStrictEqual(diff({ test: true }, { test: true, test2: true }), [
{
type: "CREATE",
path: ["test2"],
value: true,
},
]);
});
test("change raw value", () => {
assert.deepStrictEqual(diff({ test: true }, { test: false }), [
{
type: "CHANGE",
path: ["test"],
value: false,
oldValue: true,
},
]);
});
test("remove raw value", () => {
assert.deepStrictEqual(diff({ test: true, test2: true }, { test: true }), [
{
type: "REMOVE",
path: ["test2"],
oldValue: true,
},
]);
});
test("replace object with null", () => {
assert.deepStrictEqual(diff({ object: { test: true } }, { object: null }), [
{
type: "CHANGE",
path: ["object"],
value: null,
oldValue: { test: true },
},
]);
});
test("replace object with other value", () => {
assert.deepStrictEqual(
diff({ object: { test: true } }, { object: "string" }),
[
{
type: "CHANGE",
path: ["object"],
value: "string",
oldValue: { test: true },
},
]
);
});
test("equal null protype objects", () => {
assert.deepStrictEqual(diff(Object.create(null), Object.create(null)), []);
});
test("unequal null protype objects", () => {
const obj1 = Object.create(null);
const obj2 = Object.create(null);
obj2.test = true;
assert.deepStrictEqual(diff(obj1, obj2), [
{
type: "CREATE",
path: ["test"],
value: true,
},
]);
});