-
Notifications
You must be signed in to change notification settings - Fork 0
Redux & Snapshot Testing
To test the current Redux and Snapshot tests, navigate to WediumFrontend
and run the command: npm test
In order to perform Redux testing, we used the Jest framework. Essentially, the team used createStore()
before each test to ensure a consistent state. After ensuring that the state of the store was consistent we dispatched actions and then proceeded to test that the store was being updated correctly using the expect()
and getState()
statements. Please note as a means to ensure the consistent state of the store we highly encourage the use of the beforeEach()
method where one simply re-initializes the store, i.e. store = createStore(rootReducer);
Please note that we tried to perform Snapshot testing where possible. Although due to the complexity of our components and most of them being wrapped with withRouter()
made it so in some cases we proceeded to have shallow testing. Shallow testing ensures that the component is being rendered correctly, without having to worry about the details of any of the child components. Furthermore, Snapshot testing was done to track any changes to code that might have been unintentional. The basic format from Snapshot tests are as follows :
it(‘snapshot with no content’, () => ){
const tree = renderer.create(<ComponentName />).toJson();
expect(tree).toMatchSnapshot();
}
const setRouteLeaveHook = jest.fn();
let wrapper = shallow(
<{Complex component}.WrappedComponent
params={{
router: setRouteLeaveHook,
}}
/>
);
expect(wrapper).toMatchSnapshot();
Jainal Gandhi | Harman Lamba | Eric Leung | Salma Sanad
Made with love 👨👨👧👦💖