/
over.spec.js
44 lines (40 loc) · 938 Bytes
/
over.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
33
34
35
36
37
38
39
40
41
42
43
44
import {assoc} from './assoc'
import {lens} from './lens'
import {lensIndex} from './lensIndex'
import {lensPath} from './lensPath'
import {over} from './over'
import {prop} from './prop'
import {toUpper} from './toUpper'
const testObject = {
foo: 'bar',
baz: {
a: 'x',
b: 'y',
},
}
test('assoc lens', () => {
const assocLens = lens(prop('foo'), assoc('foo'))
const result = over(assocLens, toUpper, testObject)
const expected = {
...testObject,
foo: 'BAR',
}
expect(result).toEqual(expected)
})
test('path lens', () => {
const pathLens = lensPath('baz.a')
const result = over(pathLens, toUpper, testObject)
const expected = {
...testObject,
baz: {
a: 'X',
b: 'y',
},
}
expect(result).toEqual(expected)
})
test('index lens', () => {
const indexLens = lensIndex(0)
const result = over(indexLens, toUpper)(['foo', 'bar'])
expect(result).toEqual(['FOO', 'bar'])
})