February 2019
Intermediate to advanced
204 pages
4h 52m
English
A reducer is a function that returns the new state after applying the action to the previous state. Testing a reducer is no different from testing action creators. Let's create our reducers and the corresponding Jest file. We'll save our reducer file as reducers.js:
import { ADD_NEW_DOCTOR } from "./actionTypes";const initialState = [ { newDoctorData: {}, completed: false }];export default function addDoctor(state = initialState, action) { switch (action.type) { case ADD_NEW_DOCTOR: return [ { completed: false, data: action.newDoctorData }, ...state ]; default: return state; }}
Our action types will be saved as actionTypes.js:
export const ADD_NEW_DOCTOR = "ADD_NEW_DOCTOR";
Our test file will be saved in the __tests__ folder, ...
Read now
Unlock full access