-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathjestFrameworkSetup.ts
35 lines (33 loc) · 1.05 KB
/
jestFrameworkSetup.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
const diff = require('jest-diff');
expect.extend({
toEqualDocument(actual, expected) {
const pass = this.equals(actual.toJSON(), expected.toJSON());
const message = pass
? (): string =>
`${this.utils.matcherHint('.not.toEqualDocument')}\n\n` +
`Expected JSON value of document to not equal:\n ${this.utils.printExpected(
expected
)}\n` +
`Actual JSON:\n ${this.utils.printReceived(actual)}`
: (): string => {
const diffString = diff(expected, actual, {
expand: this.expand,
});
return (
`${this.utils.matcherHint('.toEqualDocument')}\n\n` +
`Expected JSON value of document to equal:\n${this.utils.printExpected(
expected
)}\n` +
`Actual JSON:\n ${this.utils.printReceived(actual)}` +
`${diffString ? `\n\nDifference:\n\n${diffString}` : ''}`
);
};
return {
pass,
actual,
expected,
message,
name: 'toEqualDocument',
};
},
});