-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvitest.setup.tsx
40 lines (31 loc) · 1.14 KB
/
vitest.setup.tsx
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
import React, { Suspense } from 'react';
import { afterEach, expect } from 'vitest';
import matchers from '@testing-library/jest-dom/matchers';
import { cleanup, render, RenderOptions } from '@testing-library/react';
import { createTheme, ThemeProvider } from '@mui/material';
expect.extend(matchers);
// https://vitest.dev/guide/migration.html#migrating-from-jest
// https://testing-library.com/docs/react-testing-library/api/#cleanup
afterEach(() => cleanup());
const customRender = (ui: React.ReactElement, options: RenderOptions = {}) => {
const theme = createTheme();
const rtl = render(ui, {
wrapper: ({ children }) => (
<Suspense fallback={null}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</Suspense>
),
...options,
});
return {
...rtl,
rerender: (ui: React.ReactElement, rerenderOptions?: RenderOptions) =>
customRender(ui, {
container: rtl.container,
...options,
...rerenderOptions,
}),
};
};
export * from '@testing-library/react';
export { customRender as render };