Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Created August 3, 2021 22:37
Show Gist options
  • Save BrianJenney/c0e993fb48d69590262a3291c5853a06 to your computer and use it in GitHub Desktop.
Save BrianJenney/c0e993fb48d69590262a3291c5853a06 to your computer and use it in GitHub Desktop.
export function renderWithRedux(component, { store } = {}) {
const rendered = render(
<BrowserRouter>
<ThemeProvider theme="bri">
<Provider store={store}>{component}</Provider>
</ThemeProvider>
</BrowserRouter>
);
// return the methods and properties from our custom render
return {
...rendered,
rerender: (el) => renderWithRedux(el, { store }),
store
};
}
// create a fake redux store with the option to add
// properties for scenarios we might want to test
export const createReduxStore = (options = {}) => {
const defaultOpts = {
currentUser: {
data: {
firstName: 'Cool Dude',
}
}
};
return {
getState: () => ({
...defaultOpts,
...options
}),
createStore: () => ({})
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment