forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle.test.js
More file actions
89 lines (67 loc) · 2.15 KB
/
toggle.test.js
File metadata and controls
89 lines (67 loc) · 2.15 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import configureMockStore from 'redux-mock-store';
import { toggleMiddleware } from '../../src/middleware/toggle';
import { TOGGLE, TOGGLE_JS, TOGGLE_MODE } from '../../src/static/constants/actions';
const next = jest.fn();
const mockStore = configureMockStore();
describe('Toggle middleware', () => {
it('should dispatch TOGGLE_JS when the payload is `js`', () => {
const mockDispatch = jest.fn();
const store = mockStore({
js: 'es5',
dispatch: mockDispatch
});
const action = { type: TOGGLE, payload: 'js' };
toggleMiddleware(store)(next)(action);
expect(store.getActions()[0]).toEqual({
type: TOGGLE_JS,
payload: 'es6'
});
expect(next).toHaveBeenCalled();
});
it('should dispatch TOGGLE_JS when the payload is `js`', () => {
const mockDispatch = jest.fn();
const store = mockStore({
js: 'es6',
dispatch: mockDispatch
});
const action = { type: TOGGLE, payload: 'js' };
toggleMiddleware(store)(next)(action);
expect(store.getActions()[0]).toEqual({
type: TOGGLE_JS,
payload: 'es5'
});
expect(next).toHaveBeenCalled();
});
it('should dispatch TOGGLE_MODE when the payload is `mode`', () => {
const mockDispatch = jest.fn();
const store = mockStore({
mode: 'dark',
dispatch: mockDispatch
});
const action = { type: TOGGLE, payload: 'mode' };
toggleMiddleware(store)(next)(action);
expect(store.getActions()[0]).toEqual({
type: TOGGLE_MODE,
payload: 'light'
});
});
it('should dispatch TOGGLE_MODE when the payload is `mode`', () => {
const mockDispatch = jest.fn();
const store = mockStore({
mode: 'light',
dispatch: mockDispatch
});
const action = { type: TOGGLE, payload: 'mode' };
toggleMiddleware(store)(next)(action);
expect(store.getActions()[0]).toEqual({
type: TOGGLE_MODE,
payload: 'dark'
});
});
it('should return _next_ when the action is not TOGGLE', () => {
const store = mockStore({});
const action = { type: 'ERROR' };
toggleMiddleware(store)(next)(action);
expect(store.getActions()[0]).toBeFalsy();
});
});