Skip to content

Instantly share code, notes, and snippets.

@aarondail
Created July 14, 2020 17:06
Show Gist options
  • Save aarondail/851d2b63f4cd1006d6ddba907e8c3917 to your computer and use it in GitHub Desktop.
Save aarondail/851d2b63f4cd1006d6ddba907e8c3917 to your computer and use it in GitHub Desktop.
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