-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-utils.tsx
70 lines (68 loc) · 2.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { render } from '@testing-library/react';
import React, { PropsWithChildren, ReactElement } from 'react';
import { MemoryRouterProvider } from 'next-router-mock/MemoryRouterProvider';
import HeadlinesProvider from './hooks/headlines';
import Layout from './components/layout';
import IsLoadingContextProvider from './hooks/use-loading-state';
import { CodingsPreferencesProvider } from './hooks/use-codings-preference';
import { NamespaceProvider } from './hooks/use-namespace';
import deDE from 'antd/lib/locale/de_DE';
import InitialHeadlinesProvider from './hooks/initial-headlines';
import { NextAdapter } from 'next-query-params';
import { QueryParamProvider } from 'use-query-params';
import FetchingQueryParamsProvider from './hooks/fetch-query-params-provider';
import ApplicationProfileQueryParamProvider from './hooks/use-application-profile-query-param-provider';
import { ConfigProvider } from 'antd';
// import InitialHeadlinesProvider from './hooks/initial-headlines';
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
const genericRender = (component: ReactElement, name: string) => {
const wrapper = ({ children }: PropsWithChildren) => {
return (
<>
<ConfigProvider locale={deDE}>
<QueryParamProvider adapter={NextAdapter}>
<ApplicationProfileQueryParamProvider>
<FetchingQueryParamsProvider>
<NamespaceProvider>
<InitialHeadlinesProvider>
<HeadlinesProvider>
<IsLoadingContextProvider>
<CodingsPreferencesProvider>
<Layout>
<MemoryRouterProvider>
{children}
</MemoryRouterProvider>
</Layout>
</CodingsPreferencesProvider>
</IsLoadingContextProvider>
</HeadlinesProvider>
</InitialHeadlinesProvider>
</NamespaceProvider>
</FetchingQueryParamsProvider>
</ApplicationProfileQueryParamProvider>
</QueryParamProvider>
</ConfigProvider>
</>
);
};
try {
return render(component, { wrapper });
} catch (e) {
console.log('error with', name);
throw e;
}
};
export const genericMatchSnapshot = (component: ReactElement, name: string) =>
expect(genericRender(component, name)).toMatchSnapshot(name);