-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
37 lines (35 loc) · 892 Bytes
/
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
// Custom matcher for number or null
expect.extend({
toBeNullOrTypeOf(received, argument) {
if (received === null || typeof received === argument) {
return {
message: () => `expected ${received} to be null or of type ${argument}`,
pass: true,
}
}
return {
message: () => `expected ${received} to be null or of type ${argument}`,
pass: false,
}
},
})
expect.extend({
toBeEnumValue(received, enumObj) {
const values = Object.values(enumObj)
const pass = values.includes(received)
if (pass) {
return {
message: () => `expected ${received} not to be one of the enum values`,
pass: true,
}
} else {
return {
message: () =>
`expected ${received} to be one of the enum values ${values.join(
', ',
)}`,
pass: false,
}
}
},
})