Skip to content

Instantly share code, notes, and snippets.

@pablospaniard
Last active February 3, 2021 15:56
Show Gist options
  • Select an option

  • Save pablospaniard/8e7bd0d6b9410409a5a4139fe9298b00 to your computer and use it in GitHub Desktop.

Select an option

Save pablospaniard/8e7bd0d6b9410409a5a4139fe9298b00 to your computer and use it in GitHub Desktop.
Render method from RTL with Store and InitalState
import React from 'react';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { render as rtlRender } from '@testing-library/react-native';
import { rootReducer } from 'store';
// you can provide initialState or the entire store that the ui is rendered with
export const renderWithStore = (
ui,
{
initialState,
store = createStore(rootReducer, initialState),
...renderOptions
} = {}
) => {
function Wrapper({ children }) {
return <Provider store={store}>{children}</Provider>;
}
return {
...rtlRender(ui, {
wrapper: Wrapper,
...renderOptions
}),
// adding `store` to the returned utilities to allow us
// to reference it in our tests (just try to avoid using
// this to test implementation details).
store
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment