-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
53 lines (45 loc) · 1.33 KB
/
index.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
45
46
47
48
49
50
51
52
53
import R from 'ramda';
import S from 'sanctuary';
import { clique } from './';
const keys = ['one', 'two'];
/**
* Takes a list of strings, and returns an object where a nullary returner
* function is attached to each key of the same name (rslt.a() //=> 'a')
*
* consts :: [String] -> Object
*/
const consts = clique(S.I, R.always);
it('should make a constant map', () => {
const C = consts(keys);
expect(R.keys(C)).toEqual(keys);
expect(R.values(C).map(x => x())).toEqual(keys);
});
/**
* Takes a list of strings, and returns an object where a equlity tester is
* attached to each key of the same name
*
* equalities :: [String] -> Object
*/
const equalities = clique(S.I, R.equals);
it('should make an equality map', () => {
const E = equalities(keys);
expect(R.mapObjIndexed(R.call, E)).toEqual({ one: true, two: true });
});
/**
* Takes a list of strings, and returns an object where a R.lensPath lens is
* attached to each key of the same name
*
* lenses :: [String] -> Object
*/
const lenses = clique(S.I, S.compose(
R.lensPath,
R.of
));
it('should make a lens map', () => {
const L = lenses(keys);
const obj = { one: { two: 'here I am' } };
const two = 'I win';
const lens = R.compose(L.one, L.two);
expect(R.view(lens, obj)).toBe(obj.one.two);
expect(R.set(lens, two, obj)).toEqual({ one: { two } });
});