-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest_setup.js
46 lines (41 loc) · 1.22 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
import { equals } from 'expect/build/jasmine_utils';
expect.extend({
toBeIterable(received, argument) {
let pass = Symbol.iterator in received;
if (pass && argument && typeof argument.asymmetricMatch === 'function') {
return { pass: argument.asymmetricMatch(received[Symbol.iterator]()), message: () => 'meh' };
}
return {
message: () =>
this.utils.matcherHint(`${pass ? '.not' : ''}.toBeIterable`) +
'\n\n' +
`expected${
pass ? ' not' : ''
} to find a [Symbol.iterator] property, but Symbol.iterator was:\n` +
` ${this.utils.printReceived(received)}`,
pass,
};
},
yields(received, ...args) {
let pass = args.reduce((pass, arg) => {
return pass && arg === received.next().value;
}, true);
const done = received.next();
pass = pass && done.done;
return {
message: () => `Didn't do the thing.`,
pass,
};
},
yieldsEqual(received, ...args) {
let pass = args.reduce((pass, arg) => {
return pass && equals(arg, received.next().value);
}, true);
const done = received.next();
pass = pass && done.done;
return {
message: () => `Didn't do the thing.`,
pass,
};
},
});