-
Notifications
You must be signed in to change notification settings - Fork 93
/
jestSetup.js
30 lines (24 loc) · 918 Bytes
/
jestSetup.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
import { matcherHint, printExpected, printReceived } from "jest-matcher-utils";
import { TextEncoder, TextDecoder } from "node:util";
import { ReadableStream } from "node:stream/web";
Object.assign(global, { TextDecoder, TextEncoder, ReadableStream });
const passMessage = (actual, expected) => () =>
`${matcherHint(".not.toMatchPath")}
Expected value not to match:
${printExpected(expected)}
Received:
${printReceived(actual)}`;
const failMessage = (actual, expected) => () =>
`${matcherHint(".toMatchPath")}
Expected value to match:
${printExpected(expected)}
Received:
${printReceived(actual)}`;
expect.extend({
toMatchPath: (actual, expected) => {
const normalised = actual.split(":").pop().replaceAll("\\", "/");
return expected === normalised
? { pass: true, message: passMessage(actual, normalised) }
: { pass: false, message: failMessage(actual, normalised) };
},
});