/
initialState.js
49 lines (40 loc) · 1.47 KB
/
initialState.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import expect from 'expect';
import {
buildInitialStoreState,
registerInitialStoreState,
getInitialStoreState
} from '../../src/initialState';
import { expectedInitialState, reducerWithNesterReducers } from '../testingData/reducers';
describe('initialState', () => {
describe('getInitialStoreState', () => {
describe('by default', () => {
it('should return null', () => {
expect(getInitialStoreState()).toBe(null);
});
});
describe('when registerInitialStoreState was called', () => {
const initialStoreState = { initialStoreStateKey: 'initialStoreStateValue' };
before(() => {
registerInitialStoreState(initialStoreState);
});
after(() => {
registerInitialStoreState(null);
});
it('should return registered value', () => {
expect(getInitialStoreState()).toEqual(initialStoreState);
});
it('should return deep clone of registered value', () => {
const initialState = getInitialStoreState();
initialState.newInitialStoreStateKey = 'newInitialStoreStateKey';
expect(getInitialStoreState().newInitialStoreStateKey)
.toNotEqual(initialState.newInitialStoreStateKey);
});
});
});
describe('buildInitialStoreState', () => {
it('should return initial state of all reducers', () => {
const initialState = buildInitialStoreState(reducerWithNesterReducers);
expect(initialState).toEqual(expectedInitialState);
});
});
});