runtipi/tests/test-utils.tsx

24 lines
1,002 B
TypeScript
Raw Permalink Normal View History

import React, { FC, ReactElement } from 'react';
import { render, RenderOptions, renderHook } from '@testing-library/react';
import { Toaster } from 'react-hot-toast';
2023-05-06 14:03:07 +00:00
import { NextIntlProvider } from 'next-intl';
import ue from '@testing-library/user-event';
2023-05-06 14:03:07 +00:00
import messages from '../src/client/messages/en.json';
const userEvent = ue.setup();
const AllTheProviders: FC<{ children: React.ReactNode }> = ({ children }) => (
2023-05-06 14:03:07 +00:00
<NextIntlProvider locale="en" messages={messages}>
2023-10-06 06:55:31 +00:00
{children}
<Toaster />
2023-05-06 14:03:07 +00:00
</NextIntlProvider>
);
const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'wrapper'>) => render(ui, { wrapper: AllTheProviders, ...options });
2023-10-06 06:55:31 +00:00
const customRenderHook = <Props, Result>(callback: (props: Props) => Result, options?: Omit<RenderOptions, 'wrapper'>) => renderHook(callback, { wrapper: AllTheProviders, ...options });
export * from '@testing-library/react';
export { customRender as render };
export { customRenderHook as renderHook };
export { userEvent };