-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup-env.js
46 lines (42 loc) · 1.17 KB
/
setup-env.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
import jestSnapshotSerializerAnsi from 'jest-snapshot-serializer-ansi'
expect.addSnapshotSerializer(jestSnapshotSerializerAnsi)
// add serializer for MutationRecord
expect.addSnapshotSerializer({
print: (record, serialize) => {
return serialize({
addedNodes: record.addedNodes,
attributeName: record.attributeName,
attributeNamespace: record.attributeNamespace,
nextSibling: record.nextSibling,
oldValue: record.oldValue,
previousSibling: record.previousSibling,
removedNodes: record.removedNodes,
target: record.target,
type: record.type,
})
},
test: value => {
// list of records will stringify to the same value
return (
Array.isArray(value) === false &&
String(value) === '[object MutationRecord]'
)
},
})
beforeAll(() => {
const originalWarn = console.warn
jest.spyOn(console, 'warn').mockImplementation((...args) => {
if (args[0] && args[0].includes && args[0].includes('deprecated')) {
return
}
originalWarn(...args)
})
})
afterEach(() => {
if (jest.isMockFunction(global.setTimeout)) {
jest.useRealTimers()
}
})
afterAll(() => {
jest.restoreAllMocks()
})