runtipi/tests/test-utils.tsx
2023-05-21 20:29:11 +02:00

22 lines
1,003 B
TypeScript

import React, { FC, ReactElement } from 'react';
import { render, RenderOptions, renderHook } from '@testing-library/react';
import { Toaster } from 'react-hot-toast';
import { NextIntlProvider } from 'next-intl';
import { TRPCTestClientProvider } from './TRPCTestClientProvider';
import messages from '../src/client/messages/en.json';
const AllTheProviders: FC<{ children: React.ReactNode }> = ({ children }) => (
<NextIntlProvider locale="en" messages={messages}>
<TRPCTestClientProvider>
{children}
<Toaster />
</TRPCTestClientProvider>
</NextIntlProvider>
);
const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'wrapper'>) => render(ui, { wrapper: AllTheProviders, ...options });
const customRenderHook = (callback: () => any, options?: Omit<RenderOptions, 'wrapper'>) => renderHook(callback, { wrapper: AllTheProviders, ...options });
export * from '@testing-library/react';
export { customRender as render };
export { customRenderHook as renderHook };