-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
44 lines (39 loc) · 997 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
37
38
39
40
41
42
43
44
// @flow
'use strict';
const expect = require('expect');
const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher');
/*::
type Input =
| void
| null
| boolean
| string
| number
| Array<Input>
| { [key: any]: Input };
*/
function isAsymmetricMatcher(obj) {
return obj['$$typeof'] === asymmetricMatcher;
}
function containDeep(input /*: Input */) {
if (typeof input === 'function') {
return input;
} else if (typeof input === 'object') {
if (Array.isArray(input)) {
return expect.arrayContaining(input.map(item => {
return containDeep(item);
}));
} else if (input instanceof RegExp) {
return expect.stringMatching(input);
} else if (input !== null && !isAsymmetricMatcher(input)) {
let obj = {};
let safeRef = input;
Object.keys(input).forEach(key => {
obj[key] = containDeep(safeRef[key]);
});
return expect.objectContaining(obj);
}
}
return input;
}
module.exports = containDeep;