-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
44 lines (38 loc) · 1.33 KB
/
jest.setup.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
import {render} from '@testing-library/react';
import React from 'react';
import {Formik} from 'formik';
import {MemoryRouter} from 'react-router-dom';
import {ChakraProvider} from '@chakra-ui/react';
import ReactSelect from 'react-select';
import {themed} from '@/theme';
// Globalize common imports to make them available in all test files
global.React = React;
let mountedComponent;
global.render = (Component, props = {}, options = {}) => {
if (!mountedComponent) {
let component = <Component {...props}/>;
if (options.router) {
component = <MemoryRouter {...options.router}>{component}</MemoryRouter>;
}
if (options.formik) {
component = <Formik onSubmit={() => {}} initialValues={options.formik}>{component}</Formik>;
}
if (options.chakra) {
component = <ChakraProvider theme={themed}>{component}</ChakraProvider>;
}
if (options.wrapper) {
component = <options.wrapper>{component}</options.wrapper>;
}
if (options.reactSelect) {
component = <ReactSelect components={component}/>;
}
mountedComponent = render(component);
}
return mountedComponent;
};
global.tearDown = () => {
if (mountedComponent) {
mountedComponent.unmount();
}
mountedComponent = undefined;
};