-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
36 lines (31 loc) · 862 Bytes
/
index.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
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';
import getType from "jest-get-type";
export 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
};
export const extend = (expect) => {
expect.extend(wrapped);
};
export default wrapped;