-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathsetupTests.js
62 lines (52 loc) · 1.69 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
61
62
/** @jest-environment setup-polly-jest/jest-environment-node */
import '@testing-library/jest-dom'
import { setupPolly } from 'setup-polly-jest'
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'
import Enzyme from 'enzyme'
import fetch from 'node-fetch'
import path from 'path'
import toDiffableHtml from 'diffable-html'
// https://github.com/mui-org/material-ui/issues/21293
export const withoutMuiID = (wrapper) =>
toDiffableHtml(
wrapper
.html()
.replace(/id="mui-[0-9]*"/g, '')
.replace(/aria-labelledby="(mui-[0-9]* *)*"/g, '')
.replace(/makeStyles-.*-[0-9]*/, '')
.replace(/MuiBox-root-.*-[0-9]*/, '')
)
Enzyme.configure({ adapter: new Adapter() })
// To stub out fetch(), we need to use node-fetch and this line:
global.fetch = fetch
// See: https://github.com/vuejs/vue-test-utils/issues/974
global.requestAnimationFrame = (cb) => cb()
// Set API URL for Sippy
process.env.REACT_APP_API_URL = 'http://localhost:8080'
// Default PollyJS mode is replay, set to record to record
// new API calls.
if (!process.env.POLLY_MODE) {
process.env.POLLY_MODE = 'replay'
}
export const setupDefaultPolly = () => {
return setupPolly({
mode: process.env.POLLY_MODE,
adapters: [require('@pollyjs/adapter-node-http')],
persister: require('@pollyjs/persister-fs'),
persisterOptions: {
fs: {
recordingsDir: path.resolve(__dirname, '../__recordings__'),
},
},
})
}
export const expectLoadingPage = (wrapper) =>
expect(wrapper.find('p').contains('Loading...'))
jest.mock('react-chartjs-2', () => ({
Bar: () => null,
Chart: () => null,
ChartComponent: () => null,
Doughnut: () => null,
Line: () => null,
PolarArea: () => null,
}))