-
Notifications
You must be signed in to change notification settings - Fork 22
/
jest.setup-tests.ts
56 lines (46 loc) · 1.71 KB
/
jest.setup-tests.ts
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
47
48
49
50
51
52
53
54
55
56
import fetch from 'cross-fetch'
const originalConsoleError = console.error
const originalConsoleWarn = console.warn
global.console.error = (message, ...optionalParams) => {
if (typeof message === 'string') {
// GraphQL mocks might not contain every property that the schema specifies.
// Apollo spams our console with it while not on production, this hides it.
if (message.match(/Missing field '.*' while writing result/gi)) {
return
}
if (
message.match(
/Warning: The current testing environment is not configured to support act(...)/gi
)
) {
return
}
}
if (typeof message === 'object' && 'message' in message && typeof message.message === 'string') {
// JSDOM doesn't always support every new CSS property (e.g. container queries)
// This hides the console.error from it.
if (message.message.match(/.*Could not parse CSS stylesheet/gi)) {
return
}
}
originalConsoleError(message, ...optionalParams)
}
global.console.warn = (message, ...optionalParams) => {
if (typeof message === 'string') {
// GraphQL mocks might not contain every property that the schema specifies.
// Apollo spams our console with it while not on production, this hides it.
if (message.match(/Missing field '.*' while writing result/gi)) {
return
}
// Tests may overlap and define the same fragments, not an issue during testing
if (message.match(/Warning: fragment with name .* already exists./gi)) {
return
}
}
if (typeof message === 'object' && 'message' in message && typeof message.message === 'string') {
}
originalConsoleWarn(message, ...optionalParams)
}
if (global.fetch === undefined) {
global.fetch = fetch
}