-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhas.test.ts
39 lines (35 loc) · 1.41 KB
/
has.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
import { testSuite, expect } from "manten";
import { nrml, testCollection } from "../../../common";
export default testSuite(async ({ describe }) => {
describe("$has", ({ test }) => {
test("works", () => {
const collection = testCollection();
collection.insert([{ a: 2 }, { b: 4 }, { c: 5 }, { a: 6 }]);
const found = nrml(collection.find({ $has: "a" }));
expect(found).toEqual([{ a: 2 }, { a: 6 }]);
});
test("works with more than one property", () => {
const collection = testCollection();
collection.insert([{ a: 2, b: 1 }, { b: 4 }, { a: 5 }, { a: 6, b: 3 }]);
const found = nrml(collection.find({ $has: ["a", "b"] }));
expect(found).toEqual([{ a: 2, b: 1 }, { a: 6, b: 3 }]);
});
test("works with $not", () => {
const collection = testCollection();
collection.insert([{ a: 2 }, { b: 4 }, { c: 5 }, { a: 6 }]);
const found = nrml(collection.find({ $not: { $has: "a" } }));
expect(found).toEqual([
{ xxx: "xxx" },
{ yyy: "yyy" },
{ zzz: "zzz" },
{ b: 4 }, { c: 5 }
]);
});
test("works with dot notation", () => {
const collection = testCollection();
collection.insert([{ a: { b: 2 } }, { a: { c: 4 } }, { a: { d: 5 } }, { a: { b: 6 } }]);
const found = nrml(collection.find({ $has: "a.b" }));
expect(found).toEqual([{ a: { b: 2 } }, { a: { b: 6 } }]);
});
});
});