diff options
author | 2024-07-10 02:06:42 +0100 | |
---|---|---|
committer | 2024-07-10 02:06:42 +0100 | |
commit | d96ea398a414595c907fde7c83027b6b1d42a0e3 (patch) | |
tree | 48b287c399570a26bad5fc4ba566bcf2e1cb8356 /src/tests/utils.tsx | |
parent | Merge pull request #635 from python-discord/jb3/deps/dep-bumps (diff) | |
parent | Add new test suite for testing authorization splash (diff) |
Merge pull request #634 from python-discord/jb3/auth/popup-and-improvements
Authorization pop-up & misc improvements
Diffstat (limited to 'src/tests/utils.tsx')
-rw-r--r-- | src/tests/utils.tsx | 36 |
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 }) + }; +} |