-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge.test.ts
41 lines (37 loc) · 1.52 KB
/
merge.test.ts
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
import { expect, testSuite } from "manten";
import { nrml, testCollection } from "../../../common";
export default testSuite(async ({ describe }) => {
describe("$merge", ({ test }) => {
test("shallow selector, deep-root update", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ a: 1 }, { $merge: { b: { d: 6 } } });
const found = nrml(collection.find({ d: 6 }));
expect(found).toEqual([{ a: 1, b: { c: 5, d: 6 } }]);
});
test("deep-root selector, deep-root update", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ a: 1, b: { c: 5 } }, { $merge: { b: { d: 6 } } });
const found = nrml(collection.find({ d: 6 }));
expect(found).toEqual([{ a: 1, b: { c: 5, d: 6 } }]);
});
test("overwrites existing properties", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update(
{ a: 1 },
{ $merge: { a: 2, b: { d: 6 } } }
);
const found = nrml(collection.find({ d: 6 }));
expect(found).toEqual([{ a: 2, b: { c: 5, d: 6 } }]);
});
test("deep selector merges deeply", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ c: 5 }, { $merge: { a: 2 } });
const found = nrml(collection.find({ a: 2 }));
expect(found).toEqual([{ a: 1, b: { c: 5, a: 2 } }]);
});
});
});