-
Notifications
You must be signed in to change notification settings - Fork 87
/
dropRepeatsWith.spec.js
101 lines (94 loc) · 1.83 KB
/
dropRepeatsWith.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
import {dropRepeatsWith as dropRepeatsWithRamda, eqProps} from 'ramda'
import {compareCombinations} from './_internals/testUtils'
import {dropRepeatsWith} from './dropRepeatsWith'
import {path} from './path'
import {prop} from './prop'
const eqI = eqProps('i')
test('happy', () => {
const list = [{i: 1}, {i: 2}, {i: 2}, {i: 3}]
const expected = [{i: 1}, {i: 2}, {i: 3}]
const result = dropRepeatsWith(eqI, list)
expect(result).toEqual(expected)
})
test('readme example', () => {
const list = [
{a: 1, b: 2},
{a: 1, b: 3},
{a: 2, b: 4},
]
const result = dropRepeatsWith(prop('a'), list)
expect(result).toEqual([{a: 1, b: 2}])
})
test('keeps elements from the left predicate input', () => {
const list = [
{
i: 1,
n: 1,
},
{
i: 1,
n: 2,
},
{
i: 1,
n: 3,
},
{
i: 4,
n: 1,
},
{
i: 4,
n: 2,
},
]
const expected = [
{
i: 1,
n: 1,
},
{
i: 4,
n: 1,
},
]
const result = dropRepeatsWith(eqI)(list)
expect(result).toEqual(expected)
})
const possiblePredicates = [
null,
undefined,
x => x + 1,
x => true,
x => false,
x => '',
path(['a', 'b']),
]
const possibleLists = [
null,
undefined,
[],
[1],
[{a: {b: 1}}, {a: {b: 1}}],
[/foo/g, /foo/g],
]
describe('brute force', () => {
compareCombinations({
firstInput: possiblePredicates,
secondInput: possibleLists,
callback: errorsCounters => {
expect(errorsCounters).toMatchInlineSnapshot(`
Object {
"ERRORS_MESSAGE_MISMATCH": 4,
"ERRORS_TYPE_MISMATCH": 14,
"RESULTS_MISMATCH": 0,
"SHOULD_NOT_THROW": 0,
"SHOULD_THROW": 0,
"TOTAL_TESTS": 42,
}
`)
},
fn: dropRepeatsWith,
fnRamda: dropRepeatsWithRamda,
})
})