-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathpush.test.js
36 lines (32 loc) · 1.11 KB
/
push.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
import push from './push'
describe('push', () => {
const getOp = value => {
const changeValue = jest.fn()
push(['foo', value], {}, { changeValue })
return changeValue.mock.calls[0][2]
}
it('should call changeValue once', () => {
const changeValue = jest.fn()
const state = {}
const result = push(['foo', 'bar'], state, { changeValue })
expect(result).toBeUndefined()
expect(changeValue).toHaveBeenCalled()
expect(changeValue).toHaveBeenCalledTimes(1)
expect(changeValue.mock.calls[0][0]).toBe(state)
expect(changeValue.mock.calls[0][1]).toBe('foo')
expect(typeof changeValue.mock.calls[0][2]).toBe('function')
})
it('should turn undefined into an array with one value', () => {
const op = getOp('bar')
const result = op(undefined)
expect(Array.isArray(result)).toBe(true)
expect(result.length).toBe(1)
expect(result[0]).toBe('bar')
})
it('should push value to end of array', () => {
const op = getOp('d')
const result = op(['a', 'b', 'c'])
expect(Array.isArray(result)).toBe(true)
expect(result).toEqual(['a', 'b', 'c', 'd'])
})
})