May 2019
Intermediate to advanced
496 pages
10h 38m
English
The reducer tests we just wrote contain a lot of repetition. In fact, the majority of reducers will follow exactly the same pattern: each action will set some new data, and ensure that the existing state is not lost.
Let's write a couple of test generator functions to do that for us, to help us dry up our tests:
export const itMaintainsExistingState = (reducer, action) => { it('maintains existing state', () => { const existing = { a: 123 }; expect(reducer(existing, action)).toMatchObject(existing); });};
import { itMaintainsExistingState } from ...Read now
Unlock full access