-
Notifications
You must be signed in to change notification settings - Fork 6
/
index-cjs.js
46 lines (40 loc) · 1.1 KB
/
index-cjs.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
const {
matcherHint,
printExpected,
printReceived,
} = require("jest-matcher-utils");
const getType = require("jest-get-type");
const toBeType = (received, expected) => {
const type = getType(received);
const pass = type === expected;
const message = pass
? () =>
matcherHint(".not.toBeType", "value", "type") +
"\n\n" +
`Expected value to be of type:\n` +
` ${printExpected(expected)}\n` +
`Received:\n` +
` ${printReceived(received)}\n`
: () =>
matcherHint(".toBeType", "value", "type") +
"\n\n" +
`Expected value to be of type:\n` +
` ${printExpected(expected)}\n` +
`Received:\n` +
` ${printReceived(received)}\n` +
`type:\n` +
` ${printReceived(type)}`;
return { pass, message };
};
const wrapped = {
toBeType,
};
const extend = (expect) => {
expect.extend(wrapped);
};
exports.toBeType = toBeType;
exports.extend = extend;
exports.default = wrapped; // es6 compat
module.exports = wrapped;
// THIS ENABLES 'setupFilesAfterEnv' in jest config file
expect.extend({ toBeType });