-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
jest.setup.ts
44 lines (42 loc) · 1.1 KB
/
jest.setup.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
jest.setTimeout(30000);
expect.extend({
toContainObject(received, argument) {
const pass = this.equals(received, expect.arrayContaining([expect.objectContaining(argument)]));
if (pass) {
return {
message: () =>
`expected ${this.utils.printReceived(
received,
)} not to contain object ${this.utils.printExpected(argument)}`,
pass: true,
};
} else {
return {
message: () =>
`expected ${this.utils.printReceived(
received,
)} to contain object ${this.utils.printExpected(argument)}`,
pass: false,
};
}
},
toBeTypeOrNull(received, classTypeOrNull) {
try {
expect(received).toEqual(expect.any(classTypeOrNull));
return {
message: () => `Ok`,
pass: true,
};
} catch (error) {
return received === null
? {
message: () => `Ok`,
pass: true,
}
: {
message: () => `expected ${received} to be ${classTypeOrNull} type or null`,
pass: false,
};
}
},
});