-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.js
95 lines (81 loc) · 2.67 KB
/
jest.setup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const { isLeft, isRight } = require("fp-ts/lib/Either");
expect.extend({
toBeLeft(received, expected) {
const matcherName = "toBeLeft";
const options = {
comment: "deep equality",
isNot: this.isNot,
promise: this.promise,
};
const { matcherHint, iterableEquality, printExpected, printReceived, printDiffOrStringify, stringify } = this.utils;
if (!isLeft(received)) {
return {
pass: false,
message: () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
`Expected: ${printReceived(received)} to be a Left`,
};
}
if (expected === undefined) {
return {
pass: true,
message: () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
`Expected: ${printExpected(expected)} not to be a Left`,
};
}
const pass = this.equals(received.left, expected, [iterableEquality]);
const message = pass
? () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
`Expected: not ${printExpected(expected)}\n` +
(stringify(expected) !== stringify(received.left) ? `Received: ${printReceived(received)}` : "")
: () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
printDiffOrStringify(expected, received.left, "Expected", "Received", this.expand !== false);
return { message, name: matcherName, pass };
},
toBeRight(received, expected) {
const matcherName = "toBeRight";
const options = {
comment: "deep equality",
isNot: this.isNot,
promise: this.promise,
};
const { matcherHint, iterableEquality, printExpected, printReceived, printDiffOrStringify, stringify } = this.utils;
if (!isRight(received)) {
return {
pass: false,
message: () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
`Expected: ${printReceived(received)} to be a Right`,
};
}
if (expected === undefined) {
return {
pass: true,
message: () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
`Expected: ${printExpected(expected)} not to be a Right`,
};
}
const pass = this.equals(received.right, expected, [iterableEquality]);
const message = pass
? () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
`Expected: not ${printExpected(expected)}\n` +
(stringify(expected) !== stringify(received.right) ? `Received: ${printReceived(received)}` : "")
: () =>
matcherHint(matcherName, undefined, undefined, options) +
"\n\n" +
printDiffOrStringify(expected, received.right, "Expected", "Received", this.expand !== false);
return { message, name: matcherName, pass };
},
});