-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.test.ts
More file actions
58 lines (50 loc) · 2.1 KB
/
set.test.ts
File metadata and controls
58 lines (50 loc) · 2.1 KB
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
import { expect, testSuite } from "manten";
import { nrml, testCollection } from "../../../common";
export default testSuite(async ({ describe }) => {
describe("$set", ({ test }) => {
test("works", () => {
const collection = testCollection();
collection.insert({ a: 1 });
collection.insert({ a: 2 });
collection.update({ a: 2 }, { $set: { b: 3 } });
const found = nrml(collection.find({ a: 2 }));
expect(found).toEqual([{ a: 2, b: 3 }]);
});
test("deep selector doesn't implicitly update a deep property", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ c: 5 }, { $set: { d: 6 } });
const found = nrml(collection.find({ d: 6 }));
expect(found).toEqual([{ a: 1, b: { c: 5 }, d: 6 }]);
});
test("will create deep objects", () => {
const collection = testCollection();
collection.insert({ a: 1 });
collection.update({ a: 1 }, { $set: { b: { c: 5 } } });
const found = nrml(collection.find({ b: { c: 5 } }));
expect(found).toEqual([{ a: 1, b: { c: 5 } }]);
});
test("does not merge objects, instead overwrites", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ a: 1 }, { $set: { b: { d: 6 } } });
const found = nrml(collection.find({ a: 1 }));
expect(found).toEqual([{ a: 1, b: { d: 6 } }]);
});
test("shorthand behavior", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 1 } });
collection.insert({ a: 2, b: { c: 2 } });
collection.update({ b: { c: 2 }}, { $set: 11 });
const found = nrml(collection.find({ a: 2 }));
expect(found).toEqual([{ a: 2, b: { c: 11 } }]);
});
test("works with dot notation", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 1 } });
collection.update({ "b.c": 1 }, { $set: { "b.c": 2 } });
const found = nrml(collection.find({ "b.c": 2 }));
expect(found).toEqual([{ a: 1, b: { c: 2 } }]);
});
});
});