July 2017
Intermediate to advanced
300 pages
5h 43m
English
Actually, that's quite simple with action creators because they are pure functions. We pass in an input according to the function interface and verify the output:
./js/Actions/index.spec.js
import { createStore } from "redux"; import { toggleRecording } from "./index"; describe( "Action creators", () => { describe( "toggleRecording", () => { it( "should return a valid action", () => { const FLAG = true, action = toggleRecording( FLAG ); expect( action.payload ).toEqual( { toggle: FLAG } ); }); }); });
We have written a test for the toggleRecording function. We assert the fact that the function produces an action object with { toggle: FLAG } in the payload. As mentioned in the previous chapter, any action is ...
Read now
Unlock full access