-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
34 lines (31 loc) · 848 Bytes
/
jest.setup.js
File metadata and controls
34 lines (31 loc) · 848 Bytes
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
import React from 'react';
import {render} from '@testing-library/react';
import {Formik} from 'formik';
import {MemoryRouter} from 'react-router-dom';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
global.React = React;
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 0
}
}
});
global.render = (Component, props = {}, options = {}) => {
let component = (
<QueryClientProvider client={queryClient}>
<Component {...props} />
</QueryClientProvider>
);
if (options.router) {
component = <MemoryRouter {...options.router}>{component}</MemoryRouter>;
}
if (options.formik) {
component = (
<Formik onSubmit={() => ({})} initialValues={options.formik.initialValues}>
{component}
</Formik>
);
}
return render(component);
};