Last active
February 3, 2021 15:56
-
-
Save pablospaniard/8e7bd0d6b9410409a5a4139fe9298b00 to your computer and use it in GitHub Desktop.
Render method from RTL with Store and InitalState
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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