summaryrefslogtreecommitdiff
path: root/client/src/renderWithProviders.tsx
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2024-09-27 08:43:02 -0700
committerMichael Hunteman <michael@huntm.net>2024-09-27 08:43:02 -0700
commita88f613da7e5567dbfdebd7df94f94507c47c6b5 (patch)
treeb10a6c1640c11672a940f8fa71cdf3d3485135d4 /client/src/renderWithProviders.tsx
parent7ccca5ca18200388d10fca33a1d7095a0abfcd36 (diff)
Add vitests
Diffstat (limited to 'client/src/renderWithProviders.tsx')
-rw-r--r--client/src/renderWithProviders.tsx28
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 }) };
+}