-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsetupTests.js
60 lines (51 loc) · 1.51 KB
/
setupTests.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import '@testing-library/jest-native/extend-expect'
import { TextEncoder } from 'util'
import * as consoleFailTestModule from 'console-fail-test'
import { toHaveNoViolations } from 'jest-axe'
import { configure } from 'reassure'
import { queryCache } from './reactQueryProviderHOC'
// Configuration for performance tests
configure({ testingLibrary: 'react-native' })
global.expect.extend(toHaveNoViolations)
global.TextEncoder = TextEncoder
consoleFailTestModule.cft({
testFramework: 'jest',
spyLibrary: 'jest',
console: {
debug: false,
error: false,
log: false,
warn: false,
},
})
global.afterEach(async () => {
queryCache.clear()
})
// AbortController needs to be mocked because it is not supported in our current version of Jest
global.AbortController = jest.fn(() => ({
signal: {},
abort: jest.fn(),
}))
// WEB MOCKS
// To replicate the browser behaviour in our node test environement (jsdom), we have to make the following mocks :
global.GeolocationPositionError = {
PERMISSION_DENIED: 1,
POSITION_UNAVAILABLE: 2,
TIMEOUT: 3,
}
const geolocation = {
getCurrentPosition: jest.fn((success) =>
Promise.resolve(success({ coords: { latitude: 48.85, longitude: 2.29 } }))
),
}
const permissions = {
query: jest.fn(async () => ({ state: 'granted' })),
}
const share = jest.fn()
if (global.navigator) {
global.navigator.geolocation = geolocation
global.navigator.permissions = permissions
global.navigator.share = share
} else {
global.navigator = { geolocation, permissions, share }
}