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

eqProps.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { eqProps as eqPropsRamda } from 'ramda'
import { compareCombinations } from './_internals/testUtils.js'import { eqProps } from './eqProps.js'
const obj1 = { a : 1, b : 2,}const obj2 = { a : 1, b : 3,}
test('props are equal', () => { const result = eqProps( 'a', obj1, obj2 ) expect(result).toBeTrue()})
test('props are not equal', () => { const result = eqProps( 'b', obj1, obj2 ) expect(result).toBeFalse()})
test('prop does not exist', () => { const result = eqProps( 'c', obj1, obj2 ) expect(result).toBeTrue()})
test('can handle null or undefined object', () => { expect(eqProps( 'value', { value : 0 }, null )).toBeFalse() expect(eqProps( 'value', { value : 0 }, undefined )).toBeFalse() expect(eqProps( 'value', null, { value : 0 } )).toBeFalse() expect(eqProps( 'value', undefined, { value : 0 } )).toBeFalse() expect(eqProps( 'value', undefined, { value : undefined } )).toBeTrue() expect(eqProps( 'value', null, { value : undefined } )).toBeTrue() expect(eqProps( 'value', { value : undefined }, undefined )).toBeTrue() expect(eqProps( 'value', { value : undefined }, null )).toBeTrue() expect(eqProps( 'value', {}, null )).toBeTrue() expect(eqProps( 'value', {}, undefined )).toBeTrue() expect(eqProps( 'value', null, {} )).toBeTrue() expect(eqProps( 'value', undefined, {} )).toBeTrue()})
const possibleProps = [ 'a', 'a.b', null, false, 0, 1, {}, [] ]
const possibleObjects = [ { a : 1 }, { a : 1, b : 2, }, {}, [], null, { a : { b : 1 }, c : 2, }, { a : { b : 1 }, c : 3, }, { a : { b : 2 } },]
describe('brute force', () => { let totalTestsCounter = 0
compareCombinations({ firstInput : possibleProps, setCounter : () => totalTestsCounter++, callback : errorsCounters => { expect(errorsCounters).toMatchInlineSnapshot(` { "ERRORS_MESSAGE_MISMATCH": 0, "ERRORS_TYPE_MISMATCH": 0, "RESULTS_MISMATCH": 0, "SHOULD_NOT_THROW": 0, "SHOULD_THROW": 120, "TOTAL_TESTS": 512, } `) }, secondInput : possibleObjects, thirdInput : possibleObjects, fn : eqProps, fnRamda : eqPropsRamda, })})
rambda

Version Info

Tagged at
2 months ago