-
Notifications
You must be signed in to change notification settings - Fork 0
/
enhancer.test.js
34 lines (32 loc) · 1.17 KB
/
enhancer.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
32
33
34
import { enhancer } from '../src'
function mockCreateStore (initialState) {
const mockStore = {}
mockStore.subscribe = func => mockStore.subscription = func
mockStore.getState = jest.fn(() => initialState)
return mockStore
}
describe('enhancer()', () => {
it('adds a store subscription that calls store.getState()', () => {
const initialState = { sessions: {} }
const enhance = enhancer()
const createStore = enhance(mockCreateStore)
const store = createStore(initialState)
expect(store.subscription).toBeDefined()
store.subscription()
expect(store.getState).toHaveBeenCalled()
})
it('subscription throws when session state is not found', () => {
const initialState = {}
const enhance = enhancer()
const createStore = enhance(mockCreateStore)
const store = createStore(initialState)
expect(store.subscription).toBeDefined()
expect(() => store.subscription()).toThrow()
})
it('skips the store subscription if persist option is false', () => {
const enhance = enhancer({ persist: false })
const createStore = enhance(mockCreateStore)
const store = createStore()
expect(store.subscription).not.toBeDefined()
})
})