-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
46 lines (36 loc) · 1.18 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
import value from './index'
describe('value', () => {
describe('Initial state', () => {
it('allows setting a custom value', () => {
const reducer = value({}, 'foobar')
const nextState = reducer(undefined, { type: 'DUMMY_ACTION' })
expect(nextState).toEqual('foobar')
})
it('has `null` as default', () => {
const reducer = value({})
const nextState = reducer(undefined, { type: 'DUMMY_ACTION' })
expect(nextState).toEqual(null)
})
})
describe('Actions', () => {
describe('set', () => {
it('works', () => {
const reducer = value({ set: 'SET' })
const nextState = reducer(undefined, { type: 'SET', payload: 5 })
expect(nextState).toEqual(5)
})
})
describe('reset', () => {
it('with initial state', () => {
const reducer = value({ reset: 'RESET' }, 33)
const nextState = reducer(undefined, { type: 'RESET' })
expect(nextState).toEqual(33)
})
it('without initial state', () => {
const reducer = value({ reset: 'RESET' })
const nextState = reducer(undefined, { type: 'RESET' })
expect(nextState).toEqual(null)
})
})
})
})