deno.land / x / rambda@v9.1.1 / source / forEach.spec.js

forEach.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
import { forEach } from './forEach.js'import { type } from './type.js'
test('happy', () => { const sideEffect = {} forEach(x => sideEffect[ `foo${ x }` ] = x + 10)([ 1, 2 ])
expect(sideEffect).toEqual({ foo1 : 11, foo2 : 12, })})
test('iterate over object', () => { const obj = { a : 1, b : [ 1, 2 ], c : { d : 7 }, f : 'foo', } const result = {} const returned = forEach(( val, prop, inputObj ) => { expect(type(inputObj)).toBe('Object') result[ prop ] = `${ prop }-${ type(val) }` })(obj)
const expected = { a : 'a-Number', b : 'b-Array', c : 'c-Object', f : 'f-String', }
expect(result).toEqual(expected) expect(returned).toEqual(obj)})
test('with empty list', () => { const list = [] const result = forEach(x => x * x)(list)
expect(result).toEqual(list)})
test('with wrong input', () => { const list = undefined const result = forEach(x => x * x)(list)
expect(result).toBeUndefined()})
test('returns the input', () => { const list = [ 1, 2, 3 ] const result = forEach(x => x * x)(list)
expect(result).toEqual(list)})
rambda

Version Info

Tagged at
2 months ago