-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
38 lines (36 loc) · 1.09 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
/* globals expect */
// should not require internals but is the only way to make it work on nested instances
const { equals } = require('expect/build/jasmineUtils');
const { diff: diffDefault } = require('jest-diff');
require('util').inspect.defaultOptions.depth = 8;
expect.extend({
toContainObject(receivedParam, argument) {
const received = (() => {
if (Array.isArray(receivedParam)) return receivedParam;
return [receivedParam];
})();
const pass = (() => {
if (Array.isArray(argument)) {
return equals(received,
expect.arrayContaining(argument.map(arg => expect.objectContaining(arg)))
);
}
return 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: () => (diffDefault(received, argument)),
pass: false
}
}
}
});