aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tests/utils.tsx36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/tests/utils.tsx b/src/tests/utils.tsx
new file mode 100644
index 0000000..011291a
--- /dev/null
+++ b/src/tests/utils.tsx
@@ -0,0 +1,36 @@
+/** @jsx jsx */
+import { jsx } from "@emotion/react";
+import { PropsWithChildren } from "react";
+import { render } from "@testing-library/react";
+import type { RenderOptions } from "@testing-library/react";
+import { Provider } from "react-redux";
+
+import type { AppStore, RootState } from "../store";
+import { setupStore } from "../store";
+
+interface ExtendedRenderOptions extends Omit<RenderOptions, "queries"> {
+ preloadedState?: Partial<RootState>
+ store?: AppStore
+}
+
+export function renderWithProviders(
+ ui: React.ReactElement,
+ extendedRenderOptions: ExtendedRenderOptions = {}
+) {
+ const {
+ preloadedState = {},
+ // Automatically create a store instance if no store was passed in
+ store = setupStore(preloadedState),
+ ...renderOptions
+ } = extendedRenderOptions;
+
+ const Wrapper = ({ children }: PropsWithChildren) => (
+ <Provider store={store}>{children}</Provider>
+ );
+
+ // Return an object with the store and all of RTL"s query functions
+ return {
+ store,
+ ...render(ui, { wrapper: Wrapper, ...renderOptions })
+ };
+}