Write Tests For Your Reducers#
Reducer Tests#
Since reducers are pure functions with input and output, we can write unit tests for them.
We will start by adding a test for the ADD_TODO
action in a file called reducers/faq.test.js
:
1import faq from "./faq";
2
3describe("faq", () => {
4 it("is able to handle the add faq item action", () => {
5 expect(
6 faq([], {
7 type: "ADD_FAQ_ITEM",
8 question: "What is the answer to life the universe and everything?",
9 answer: 42
10 })
11 ).toEqual([{
12 question: "What is the answer to life the universe and everything?",
13 answer: 42
14 }]);
15 });
16});
Exercise#
Add the unit tests for the edit and delete actions for the reducer.