-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjest.extentions.js
46 lines (45 loc) · 1.2 KB
/
jest.extentions.js
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
const Maybe = require('folktale/maybe');
const { equals } = require('ramda');
expect.extend({
toBeNothing(received) {
if (Maybe.hasInstance(received)) {
return received.matchWith({
Just: () => ({
message: () => `${received} should be instance of Maybe.Nothing`,
pass: false,
}),
Nothing: () => ({
message: () => `${received} is instance of Maybe.Nothing`,
pass: true,
}),
});
} else {
return {
message: () => `${received} should be instance of Maybe`,
pass: false,
};
}
},
toBeJust(received, expected) {
if (Maybe.hasInstance(received)) {
return received.matchWith({
Just: ({ value }) => ({
message: () =>
`${received} is ${
equals(value, expected) ? '' : 'not'
} equal to ${expected}`,
pass: equals(value, expected),
}),
Nothing: () => ({
message: () => `${received} should to be instance of Maybe.Just`,
pass: false,
}),
});
} else {
return {
message: () => `${received} should to be instance of Maybe`,
pass: false,
};
}
},
});