Created
July 14, 2020 17:06
-
-
Save aarondail/851d2b63f4cd1006d6ddba907e8c3917 to your computer and use it in GitHub Desktop.
This file contains 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 * as React from 'react'; | |
import { render } from 'react-native-testing-library'; | |
import { Provider } from 'react-redux'; | |
import { createStore } from 'redux'; | |
import { MyContainerComponent, MyPresentationalComponent } from '...'; | |
// Create a real redux store, with your reducers and middleware, and a useful initial | |
// state tree... | |
const store = createStore(...); | |
// Note this test only makes sense if MyPresentationalComponent is a PureComponent | |
test('MyPresentationalComponent should not be re-rendered when any misc action is dispatched ', () => { | |
const wrapper = render( | |
<Provider store={store}> | |
<MyContainerComponent /> | |
</Provider> | |
); | |
const presentationalComponentInstance = wrapper.getByType(MyPresentationalComponent).instance; | |
const renderSpy = jest.spyOn(presentationalComponentInstance, 'render'); | |
store.dispatch({ type: 'DUMMY_ACTION ' }); | |
// render should not have been called... if it was that means MyPresentationalComponent | |
// is getting changed props when it shouldn't be. | |
expect(renderSpy).toHaveBeenCalledTimes(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment