-
Notifications
You must be signed in to change notification settings - Fork 86
/
update.spec.js
32 lines (26 loc) · 877 Bytes
/
update.spec.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
import {update} from './update'
const list = [1, 2, 3]
test('happy', () => {
const newValue = 8
const index = 1
const result = update(index, newValue, list)
const curriedResult = update(index, newValue)(list)
const tripleCurriedResult = update(index)(newValue)(list)
const expected = [1, 8, 3]
expect(result).toEqual(expected)
expect(curriedResult).toEqual(expected)
expect(tripleCurriedResult).toEqual(expected)
})
test('list has no such index', () => {
const newValue = 8
const index = 10
const result = update(index, newValue, list)
expect(result).toEqual(list)
})
test('with negative index', () => {
expect(update(-1, 10, [1])).toEqual([10])
expect(update(-1, 10, [])).toEqual([])
expect(update(-1, 10, list)).toEqual([1, 2, 10])
expect(update(-2, 10, list)).toEqual([1, 10, 3])
expect(update(-3, 10, list)).toEqual([10, 2, 3])
})