forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.test.js
More file actions
57 lines (47 loc) · 1.2 KB
/
store.test.js
File metadata and controls
57 lines (47 loc) · 1.2 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
import {
TOGGLE_JS,
TOGGLE_MODE
} from '../../src/static/constants/actions';
import { loadState, saveState } from '../../src/helpers/localStorage';
describe('Store', () => {
beforeEach(() => {
jest.resetModules();
window.localStorage.clear();
});
it('should work without saved state', () => {
const {
default: store,
initialState
} = require('../../src/store');
expect(store.getState()).toMatchObject(initialState);
});
it('should load saved state from localStorage', () => {
const savedState = {
mode: 'light',
js: 'es6'
};
saveState(savedState);
const state = require('../../src/store').default.getState();
expect(state.mode).toBe('light');
expect(state.js).toBe('es6');
});
it('should save state to localStorage', () => {
const toggleJSAction = {
type: TOGGLE_JS,
payload: 'es6'
};
const toggleModeAction = {
type: TOGGLE_MODE,
payload: 'light'
};
const {
default: store
} = require('../../src/store');
store.dispatch(toggleJSAction);
store.dispatch(toggleModeAction);
expect(loadState()).toMatchObject({
mode: 'light',
js: 'es6'
});
});
});