deno.land / x / rambda@v9.1.1 / source / chain.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
54
55
56
57
58
59
60
61
62
63
64
import { chain as chainRamda } from 'ramda'
import { chain } from './chain.js'
const duplicate = n => [ n, n ]
test('happy', () => { const fn = x => [ x * 2 ] const list = [ 1, 2, 3 ]
const result = chain(fn, list)
expect(result).toEqual([ 2, 4, 6 ])})
test('maps then flattens one level', () => { expect(chain(duplicate, [ 1, 2, 3 ])).toEqual([ 1, 1, 2, 2, 3, 3 ])})
test('maps then flattens one level - curry', () => { expect(chain(duplicate)([ 1, 2, 3 ])).toEqual([ 1, 1, 2, 2, 3, 3 ])})
test('flattens only one level', () => { const nest = n => [ [ n ] ] expect(chain(nest, [ 1, 2, 3 ])).toEqual([ [ 1 ], [ 2 ], [ 3 ] ])})
test('can compose', () => { function dec(x){ return [ x - 1 ] } function times2(x){ return [ x * 2 ] }
const mdouble = chain(times2) const mdec = chain(dec) expect(mdec(mdouble([ 10, 20, 30 ]))).toEqual([ 19, 39, 59 ])})
test('@types/ramda broken test', () => { const score = { maths : 90, physics : 80, }
const calculateTotal = score => { const { maths, physics } = score
return maths + physics }
const assocTotalToScore = (total, score) => ({ ...score, total, })
const calculateAndAssocTotalToScore = chainRamda(assocTotalToScore, calculateTotal) expect(() => calculateAndAssocTotalToScore(score)).toThrowErrorMatchingInlineSnapshot('"fn(...) is not a function"')})
rambda

Version Info

Tagged at
2 months ago