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

modify.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { modify as modifyRamda } from 'ramda'
import { compareCombinations, FALSY_VALUES } from './_internals/testUtils.js'import { add } from './add.js'import { compose } from './compose.js'import { modify } from './modify.js'
const person = { name : 'foo', age : 20,}
test('happy', () => { expect(modify( 'age', x => x + 1, person )).toEqual({ name : 'foo', age : 21, })})
test('property is missing', () => { expect(modify( 'foo', x => x + 1, person )).toEqual(person)})
test('adjust if `array` at the given key with the `transformation` function', () => { expect(modify( 1, add(1), [ 100, 1400 ] )).toEqual([ 100, 1401 ])})
describe('ignores transformations if the input value is not Array and Object', () => { ;[ 42, undefined, null, '' ].forEach(value => { it(`${ value }`, () => { expect(modify( 'a', add(1), value )).toEqual(value) }) })})
const possibleProperties = [ ...FALSY_VALUES, 'foo', 0 ]const possibleTransformers = [ ...FALSY_VALUES, add(1), add('foo'), compose, String,]const possibleObjects = [ ...FALSY_VALUES, {}, [ 1, 2, 3 ], { a : 1, foo : 2, }, { a : 1, foo : [ 1 ], }, { a : 1, foo : 'bar', },]
describe('brute force', () => { compareCombinations({ fn : modify, fnRamda : modifyRamda, firstInput : possibleProperties, secondInput : possibleTransformers, thirdInput : possibleObjects, callback : errorsCounters => { expect(errorsCounters).toMatchInlineSnapshot(` { "ERRORS_MESSAGE_MISMATCH": 0, "ERRORS_TYPE_MISMATCH": 0, "RESULTS_MISMATCH": 0, "SHOULD_NOT_THROW": 0, "SHOULD_THROW": 0, "TOTAL_TESTS": 630, } `) }, })})
rambda

Version Info

Tagged at
2 months ago