-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-utils.tsx
49 lines (44 loc) · 1.44 KB
/
test-utils.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
41
42
43
44
45
46
47
48
49
import { type RenderOptions, render } from "@testing-library/react";
import { RouterContext } from "next/dist/shared/lib/router-context.shared-runtime";
import type { NextRouter } from "next/router";
import type { FC, ReactElement } from "react";
import type { PropsWithChildrenOnly } from "src/@types/react";
import { CSSRootVariables } from "src/styles/cssVariables";
import { GlobalStyles } from "src/styles/global";
const mockRouter: NextRouter = {
basePath: "/",
pathname: "/",
route: "/",
query: {},
asPath: "/",
locale: "",
push: jest.fn(() => Promise.resolve(true)),
replace: jest.fn(() => Promise.resolve(true)),
reload: jest.fn(() => Promise.resolve(true)),
prefetch: jest.fn(() => Promise.resolve()),
back: jest.fn(() => Promise.resolve(true)),
beforePopState: jest.fn(() => Promise.resolve(true)),
isFallback: false,
isLocaleDomain: false,
isPreview: false,
isReady: false,
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
},
forward: jest.fn(() => Promise.resolve(true)),
};
const Providers: FC<PropsWithChildrenOnly> = ({ children }) => (
<RouterContext.Provider value={mockRouter}>
<CSSRootVariables />
<GlobalStyles />
{children}
</RouterContext.Provider>
);
const customRender = (
ui: ReactElement,
options?: Omit<RenderOptions, "queries">,
) => render(ui, { wrapper: Providers, ...options });
export * from "@testing-library/react";
export { customRender as render };