-
Notifications
You must be signed in to change notification settings - Fork 224
/
test-env.js
41 lines (32 loc) · 909 Bytes
/
test-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
/**
* Set up globals
*/
// jQuery
import nock from 'nock'
import enableHooks from 'jest-react-hooks-shallow'
import '@testing-library/jest-dom'
// Google Tag Manager dataLayer
global.dataLayer = {
push: jest.fn()
}
// https://stackoverflow.com/questions/42677387/jest-returns-network-error-when-doing-an-authenticated-request-with-axios/43020260#43020260
global.XMLHttpRequest = undefined
/**
* Set up console.error override
*/
const { error } = console
const consoleError = function errorOverride(message) {
// eslint-disable-next-line prefer-rest-params
error.apply(console, arguments) // Keep default behaviour
throw (message instanceof Error ? message : new Error(message))
}
console.error = consoleError
nock.cleanAll()
nock.disableNetConnect()
// Mock toast provider
window.reactToastProvider = {
current: {
add: jest.fn()
}
}
enableHooks(jest, { dontMockByDefault: true })