Unit-testing Redux
We have already fiddled with the Jest testing framework in Chapter 4, Chat System with Electron and React: Enhancement, Testing, and Delivery (Writing Unit-tests section). Redux introduces new concepts, such as actions and reducers. Now, we are going to unit-test them.
As you may remember, to run Jest, we need to configure Babel:
.babelrc
{ "presets": [ ["env", { "targets": { "node": 7 }, "useBuiltIns": true }], "react", "stage-3" ], "plugins": [ "transform-class-properties", "transform-decorators-legacy" ] }
Again, with env
preset, we target Babel on Node.js 7 and enable the extra plugins we used in the webpack configuration.
Testing action creator
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"; ...