forked from adrianmcli/js-state-encapsulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_combine_reducers.test.js
31 lines (27 loc) · 1.07 KB
/
05_combine_reducers.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { createStore, countReducer } = require("./04_redux");
const { todoReducer, combineReducers } = require("./05_combine_reducers");
describe("redux revisited tests", () => {
test("todoReducer", () => {
const result1 = todoReducer([], { type: "ADD_TODO", text: "Buy bread" });
const result2 = todoReducer(["Buy bread"], {
type: "ADD_TODO",
text: "Buy milk",
});
expect(result1).toEqual(["Buy bread"]);
expect(result2).toEqual(["Buy bread", "Buy milk"]);
});
test("combineReducers", () => {
const rootReducer = combineReducers({
count: countReducer,
todos: todoReducer,
});
const { getState, dispatch } = createStore(rootReducer);
expect(getState()).toEqual({ count: 0, todos: [] });
dispatch({ type: "INCREMENT" });
dispatch({ type: "ADD_TODO", text: "Buy bread" });
expect(getState()).toEqual({ count: 1, todos: ["Buy bread"] });
dispatch({ type: "DECREMENT" });
dispatch({ type: "ADD_TODO", text: "Buy milk" });
expect(getState()).toEqual({ count: 0, todos: ["Buy bread", "Buy milk"] });
});
});