generated from mt-deva/nextjs-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.render.tsx
24 lines (18 loc) · 863 Bytes
/
test.render.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
import React from 'react';
import { render as defaultRender, RenderResult } from '@testing-library/react';
import { RouterContext } from 'next/dist/shared/lib/router-context';
import { NextRouter } from 'next/router';
import { mockRouter } from './__mocks__/NextRouter';
type DefaultParams = Parameters<typeof defaultRender>;
type RenderUI = DefaultParams[0];
type RenderOptions = DefaultParams[1] & { router?: Partial<NextRouter> };
const customRender = (ui: RenderUI, { router }: RenderOptions = {}): RenderResult => {
const Providers = ({ children }) => (
<RouterContext.Provider value={{ ...mockRouter, ...router }}>{children}</RouterContext.Provider>
);
return defaultRender(ui, { wrapper: Providers });
};
// re-export everything
export * from '@testing-library/react';
// override render method
export { customRender as render };