-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
47 lines (45 loc) · 1006 Bytes
/
index.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
42
43
44
45
46
47
import test from "ava";
import { dataInvariants } from "..";
const JSON2 = (j) => JSON.stringify(j, null, 2);
test(`exclusion patterns`, (t) => {
const data = {
deep: {
active: true,
children: [
{
lastActive: Date.now() - Math.random() * 24 * 3600 * 100,
name: "john",
},
{
lastActive: Date.now() - Math.random() * 24 * 3600 * 100,
name: "alice",
},
],
id: 1,
inf: Infinity,
ninf: -Infinity,
null: null,
},
key: "Invariant Key",
obj: {},
arr: [],
bool: Math.random() < 0.5,
signature: Math.random(),
timestamp: Date.now(),
};
const variantFilters = [
"!**/timestamp",
"!**/signature",
"!**/lastActive",
"!**/obj",
"!**/arr",
"!**/bool",
];
const invariant = dataInvariants(data, variantFilters);
try {
t.snapshot(invariant);
} catch (err) {
console.error(JSON2({ data, variantFilters }));
throw err;
}
});