-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.test.js
63 lines (59 loc) · 1.54 KB
/
apply.test.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
import test from 'ava'
import { each } from 'test-each'
import { set } from 'set-array'
const setValue = function (valueA, valueB) {
return valueB
}
const concatValue = function (valueA, valueB) {
return `${valueA}${valueB}`
}
each(
[
[['a', 'b', 'c'], { 0: 'A' }, { merge: setValue }, ['A', 'b', 'c']],
[['a', 'b', 'c'], { 1: 'B' }, { merge: setValue }, ['a', 'B', 'c']],
[['a', 'b', 'c'], { '-1': 'C' }, { merge: setValue }, ['a', 'b', 'C']],
[['a', 'b', 'c'], { 1: 'B' }, { merge: concatValue }, ['a', 'bB', 'c']],
[
['a', undefined, 'c'],
{ 1: 'B' },
{ merge: concatValue },
['a', 'undefinedB', 'c'],
],
[
['a', 'b', 'c'],
{ 4: 'E' },
{ merge: concatValue },
['a', 'b', 'c', undefined, 'undefinedE'],
],
[
['a', 'b', 'c'],
{ 1: ['B', 'C'] },
{ merge: concatValue },
['a', 'bB', 'bC', 'c'],
],
[
['a', 'b', 'c'],
{ 1: 'B', '-2': ['C'] },
{ merge: concatValue },
['a', 'bB', 'bC', 'c'],
],
[
['a', 'b', 'c'],
{ '1+': 'AB' },
{ merge: concatValue },
['a', 'AB', 'b', 'c'],
],
[['a', 'b', 'c'], { '*': 'B' }, { merge: concatValue }, ['aB', 'bB', 'cB']],
[
['a', 'b', 'c'],
{ '*': ['B', 'C'] },
{ merge: concatValue },
['aB', 'aC', 'bB', 'bC', 'cB', 'cC'],
],
],
({ title }, [inputArray, items, options, outputArray]) => {
test(`"merge" option | ${title}`, (t) => {
t.deepEqual(set(inputArray, items, options), outputArray)
})
},
)