-
Notifications
You must be signed in to change notification settings - Fork 87
/
lenses.spec.js
33 lines (29 loc) · 849 Bytes
/
lenses.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
import {compose} from './compose'
import {lensIndex} from './lensIndex'
import {lensPath} from './lensPath'
import {lensProp} from './lensProp'
import {over} from './over'
import {toUpper} from './toUpper'
import {view} from './view'
test('composed lenses', () => {
const testObject = {
foo: ['a', 'b', 'c'],
baz: {
a: 'x',
b: 'y',
},
}
const propLens = lensProp('foo')
const indexLens = lensIndex(2)
const composedLens = compose(propLens, indexLens)
const pathLens = lensPath('baz.a')
const composedPathLens = compose(lensPath('baz'), lensPath('a'))
expect(view(composedPathLens, testObject)).toEqual(
view(pathLens, testObject)
)
expect(view(composedLens)(testObject)).toEqual('c')
expect(over(composedLens, toUpper, testObject)).toEqual({
...testObject,
foo: ['a', 'b', 'C'],
})
})