1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.matches = exports.captor = exports.notEmpty = exports.notUndefined = exports.notNull = exports.objectContainsValue = exports.objectContainsKey = exports.mapHas = exports.setHas = exports.arrayIncludes = exports.isA = exports.anySet = exports.anyMap = exports.anyArray = exports.anyObject = exports.anySymbol = exports.anyFunction = exports.anyString = exports.anyNumber = exports.anyBoolean = exports.any = exports.CaptorMatcher = exports.Matcher = void 0;
|
4 |
|
5 | class Matcher {
|
6 | constructor(asymmetricMatch, description) {
|
7 | this.asymmetricMatch = asymmetricMatch;
|
8 | this.description = description;
|
9 | this.$$typeof = Symbol.for('jest.asymmetricMatcher');
|
10 | }
|
11 | toString() {
|
12 | return this.description;
|
13 | }
|
14 | toAsymmetricMatcher() {
|
15 | return this.description;
|
16 | }
|
17 | getExpectedType() {
|
18 | return 'undefined';
|
19 | }
|
20 | }
|
21 | exports.Matcher = Matcher;
|
22 | class CaptorMatcher {
|
23 | constructor() {
|
24 | this.values = [];
|
25 | this.$$typeof = Symbol.for('jest.asymmetricMatcher');
|
26 | this.asymmetricMatch = (actualValue) => {
|
27 |
|
28 | this.value = actualValue;
|
29 | this.values.push(actualValue);
|
30 | return true;
|
31 | };
|
32 | }
|
33 | getExpectedType() {
|
34 | return 'Object';
|
35 | }
|
36 | toString() {
|
37 | return 'captor';
|
38 | }
|
39 | toAsymmetricMatcher() {
|
40 | return 'captor';
|
41 | }
|
42 | }
|
43 | exports.CaptorMatcher = CaptorMatcher;
|
44 | const any = () => new Matcher(() => true, 'any()');
|
45 | exports.any = any;
|
46 | const anyBoolean = () => new Matcher((actualValue) => typeof actualValue === 'boolean', 'anyBoolean()');
|
47 | exports.anyBoolean = anyBoolean;
|
48 | const anyNumber = () => new Matcher((actualValue) => typeof actualValue === 'number' && !isNaN(actualValue), 'anyNumber()');
|
49 | exports.anyNumber = anyNumber;
|
50 | const anyString = () => new Matcher((actualValue) => typeof actualValue === 'string', 'anyString()');
|
51 | exports.anyString = anyString;
|
52 | const anyFunction = () => new Matcher((actualValue) => typeof actualValue === 'function', 'anyFunction()');
|
53 | exports.anyFunction = anyFunction;
|
54 | const anySymbol = () => new Matcher((actualValue) => typeof actualValue === 'symbol', 'anySymbol()');
|
55 | exports.anySymbol = anySymbol;
|
56 | const anyObject = () => new Matcher((actualValue) => typeof actualValue === 'object' && actualValue !== null, 'anyObject()');
|
57 | exports.anyObject = anyObject;
|
58 | const anyArray = () => new Matcher((actualValue) => Array.isArray(actualValue), 'anyArray()');
|
59 | exports.anyArray = anyArray;
|
60 | const anyMap = () => new Matcher((actualValue) => actualValue instanceof Map, 'anyMap()');
|
61 | exports.anyMap = anyMap;
|
62 | const anySet = () => new Matcher((actualValue) => actualValue instanceof Set, 'anySet()');
|
63 | exports.anySet = anySet;
|
64 | const isA = (clazz) => new Matcher((actualValue) => actualValue instanceof clazz, 'isA()');
|
65 | exports.isA = isA;
|
66 | const arrayIncludes = (arrayVal) => new Matcher((actualValue) => Array.isArray(actualValue) && actualValue.includes(arrayVal), 'arrayIncludes()');
|
67 | exports.arrayIncludes = arrayIncludes;
|
68 | const setHas = (arrayVal) => new Matcher((actualValue) => (0, exports.anySet)().asymmetricMatch(actualValue) && actualValue.has(arrayVal), 'setHas()');
|
69 | exports.setHas = setHas;
|
70 | const mapHas = (mapVal) => new Matcher((actualValue) => (0, exports.anyMap)().asymmetricMatch(actualValue) && actualValue.has(mapVal), 'mapHas()');
|
71 | exports.mapHas = mapHas;
|
72 | const objectContainsKey = (key) => new Matcher((actualValue) => (0, exports.anyObject)().asymmetricMatch(actualValue) && actualValue[key] !== undefined, 'objectContainsKey()');
|
73 | exports.objectContainsKey = objectContainsKey;
|
74 | const objectContainsValue = (value) => new Matcher((actualValue) => (0, exports.anyObject)().asymmetricMatch(actualValue) && Object.values(actualValue).includes(value), 'objectContainsValue()');
|
75 | exports.objectContainsValue = objectContainsValue;
|
76 | const notNull = () => new Matcher((actualValue) => actualValue !== null, 'notNull()');
|
77 | exports.notNull = notNull;
|
78 | const notUndefined = () => new Matcher((actualValue) => actualValue !== undefined, 'notUndefined()');
|
79 | exports.notUndefined = notUndefined;
|
80 | const notEmpty = () => new Matcher((actualValue) => actualValue !== null && actualValue !== undefined && actualValue !== '', 'notEmpty()');
|
81 | exports.notEmpty = notEmpty;
|
82 | const captor = () => new CaptorMatcher();
|
83 | exports.captor = captor;
|
84 | const matches = (matcher) => new Matcher(matcher, 'matches()');
|
85 | exports.matches = matches;
|