diff options
author | Michael Hunteman <michael@huntm.net> | 2024-09-27 08:43:02 -0700 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2024-09-27 08:43:02 -0700 |
commit | a88f613da7e5567dbfdebd7df94f94507c47c6b5 (patch) | |
tree | b10a6c1640c11672a940f8fa71cdf3d3485135d4 /client/src/renderWithProviders.tsx | |
parent | 7ccca5ca18200388d10fca33a1d7095a0abfcd36 (diff) |
Add vitests
Diffstat (limited to 'client/src/renderWithProviders.tsx')
-rw-r--r-- | client/src/renderWithProviders.tsx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/client/src/renderWithProviders.tsx b/client/src/renderWithProviders.tsx new file mode 100644 index 0000000..476fdb1 --- /dev/null +++ b/client/src/renderWithProviders.tsx @@ -0,0 +1,28 @@ +import React, { PropsWithChildren, ReactElement } from 'react'; +import { render } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import setupStore from './store'; +import type { AppStore, RootState } from './store'; +import type { RenderOptions } from '@testing-library/react'; + +interface ExtendedRenderOptions extends Omit<RenderOptions, 'queries'> { + preloadedState?: Partial<RootState>; + store?: AppStore; +} + +export function renderWithProviders( + ui: ReactElement, + extendedRenderOptions: ExtendedRenderOptions = {} +) { + const { + preloadedState = {}, + store = setupStore(preloadedState), + ...renderOptions + } = extendedRenderOptions; + + const Wrapper = ({ children }: PropsWithChildren) => ( + <Provider store={store}>{children}</Provider> + ); + + return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) }; +} |