|
1 | 1 | /* eslint-env jest */
|
2 | 2 | import { difference } from 'array'
|
3 | 3 | import { immutaTest } from 'test.utils'
|
4 |
| - |
5 | 4 | describe('Difference', () => {
|
6 |
| - |
7 | 5 | it('should remove intersecting elements', () => {
|
8 |
| - immutaTest((input, path) => { |
9 |
| - const output = difference(input, path, [3, 4]) |
| 6 | + immutaTest({ |
| 7 | + nested: { |
| 8 | + prop: [ |
| 9 | + 1, |
| 10 | + 2, |
| 11 | + 3, |
| 12 | + ], |
| 13 | + }, |
| 14 | + other: {}, |
| 15 | + }, ['nested.prop'], (input, path) => { |
| 16 | + const output = difference(input, path, [ |
| 17 | + 3, |
| 18 | + 4, |
| 19 | + ]) |
10 | 20 | expect(output).toEqual({
|
11 |
| - nested: { prop: [1, 2] }, |
| 21 | + nested: { |
| 22 | + prop: [ |
| 23 | + 1, |
| 24 | + 2, |
| 25 | + ], |
| 26 | + }, |
12 | 27 | other: {},
|
13 | 28 | })
|
14 | 29 | return output
|
15 |
| - }, { |
16 |
| - nested: { prop: [1, 2, 3] }, |
17 |
| - other: {}, |
18 |
| - }, 'nested.prop') |
| 30 | + }) |
19 | 31 | })
|
20 |
| - |
21 | 32 | it('should remove intersecting elements from several arrays', () => {
|
22 |
| - immutaTest((input, path) => { |
| 33 | + immutaTest({ |
| 34 | + nested: { |
| 35 | + prop: [ |
| 36 | + 1, |
| 37 | + 2, |
| 38 | + 3, |
| 39 | + 4, |
| 40 | + ], |
| 41 | + }, |
| 42 | + other: {}, |
| 43 | + }, ['nested.prop'], (input, path) => { |
23 | 44 | const output = difference(input, path, [1], [2])
|
24 | 45 | expect(output).toEqual({
|
25 |
| - nested: { prop: [3, 4] }, |
| 46 | + nested: { |
| 47 | + prop: [ |
| 48 | + 3, |
| 49 | + 4, |
| 50 | + ], |
| 51 | + }, |
26 | 52 | other: {},
|
27 | 53 | })
|
28 | 54 | return output
|
29 |
| - }, { |
30 |
| - nested: { prop: [1, 2, 3, 4] }, |
31 |
| - other: {}, |
32 |
| - }, 'nested.prop') |
| 55 | + }) |
33 | 56 | })
|
34 |
| - |
35 | 57 | it('should replace deep undefined with array', () => {
|
36 |
| - immutaTest((input, path) => { |
37 |
| - const output = difference(input, path, [1, 2]) |
| 58 | + immutaTest(undefined, ['nested.prop'], (input, path) => { |
| 59 | + const output = difference(input, path, [ |
| 60 | + 1, |
| 61 | + 2, |
| 62 | + ]) |
38 | 63 | expect(output).toEqual({ nested: { prop: [] } })
|
39 | 64 | return output
|
40 |
| - }, undefined, 'nested.prop') |
| 65 | + }) |
41 | 66 | })
|
42 | 67 | })
|
0 commit comments