Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit b3a27bd

Browse files
frinyvonnicknlepage
authored andcommitted
✅ Reorder immutaTest params (#259)
* 🚧 Start refactoring immutaTest * 🐛 Add paths in callback call * ✅ Reorder immutaTest params in core package * ✅ Reorder immutaTest params in lodash package * 🔀 Fix after rebase * 🔀 Fix after rebase
1 parent 4eee0ed commit b3a27bd

File tree

90 files changed

+2262
-1213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2262
-1213
lines changed

misc/test.utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export const toRefs = object => {
1818
return refs
1919
}
2020

21-
export const immutaTest = (cb, input, ...paths) => {
21+
export const immutaTest = (input, paths, cb) => {
2222
const inputRefs = toRefs(input)
2323

24-
const output = cb(input, ...paths)
24+
const output = cb(input, paths)
2525

2626
expect(input).toBeDeep(inputRefs)
2727
expect(output).toBeDeep(inputRefs, { exclude: paths })
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,67 @@
11
/* eslint-env jest */
22
import { difference } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('Difference', () => {
6-
75
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+
])
1020
expect(output).toEqual({
11-
nested: { prop: [1, 2] },
21+
nested: {
22+
prop: [
23+
1,
24+
2,
25+
],
26+
},
1227
other: {},
1328
})
1429
return output
15-
}, {
16-
nested: { prop: [1, 2, 3] },
17-
other: {},
18-
}, 'nested.prop')
30+
})
1931
})
20-
2132
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) => {
2344
const output = difference(input, path, [1], [2])
2445
expect(output).toEqual({
25-
nested: { prop: [3, 4] },
46+
nested: {
47+
prop: [
48+
3,
49+
4,
50+
],
51+
},
2652
other: {},
2753
})
2854
return output
29-
}, {
30-
nested: { prop: [1, 2, 3, 4] },
31-
other: {},
32-
}, 'nested.prop')
55+
})
3356
})
34-
3557
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+
])
3863
expect(output).toEqual({ nested: { prop: [] } })
3964
return output
40-
}, undefined, 'nested.prop')
65+
})
4166
})
4267
})
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
/* eslint-env jest */
22
import { differenceBy } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('DifferenceBy', () => {
6-
75
it('should remove intersecting elements according to iteratee', () => {
8-
immutaTest((input, path) => {
9-
const output = differenceBy(input, path, [5.4, 2.1], Math.floor)
6+
immutaTest({
7+
nested: {
8+
prop: [
9+
1.2,
10+
3.4,
11+
5.6,
12+
],
13+
},
14+
other: {},
15+
}, ['nested.prop'], (input, path) => {
16+
const output = differenceBy(input, path, [
17+
5.4,
18+
2.1,
19+
], Math.floor)
1020
expect(output).toEqual({
11-
nested: { prop: [1.2, 3.4] },
21+
nested: {
22+
prop: [
23+
1.2,
24+
3.4,
25+
],
26+
},
1227
other: {},
1328
})
1429
return output
15-
}, {
16-
nested: { prop: [1.2, 3.4, 5.6] },
17-
other: {},
18-
}, 'nested.prop')
30+
})
1931
})
2032
})
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
/* eslint-env jest */
22
import { differenceWith } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('DifferenceWith', () => {
6-
75
it('should remove intersecting elements according to iteratee', () => {
8-
immutaTest((input, path) => {
9-
const output = differenceWith(input, path, [{ x: 2 }, { x: 3 }], (a, b) => a.x === b.x)
6+
immutaTest({
7+
nested: {
8+
prop: [{ x: 1 },
9+
{ x: 2 },
10+
],
11+
},
12+
other: {},
13+
}, ['nested.prop'], (input, path) => {
14+
const output = differenceWith(input, path, [{ x: 2 },
15+
{ x: 3 },
16+
], (a, b) => a.x === b.x)
1017
expect(output).toEqual({
1118
nested: { prop: [{ x: 1 }] },
1219
other: {},
1320
})
1421
return output
15-
}, {
16-
nested: { prop: [{ x: 1 }, { x: 2 }] },
17-
other: {},
18-
}, 'nested.prop')
22+
})
1923
})
2024
})
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,61 @@
11
/* eslint-env jest */
22
import { drop } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('Drop', () => {
6-
75
it('should drop an element at the start of the array', () => {
8-
immutaTest((input, path) => {
6+
immutaTest({
7+
nested: {
8+
prop: [
9+
1,
10+
2,
11+
3,
12+
],
13+
},
14+
other: {},
15+
}, ['nested.prop'], (input, path) => {
916
const output = drop(input, path)
1017
expect(output).toEqual({
11-
nested: { prop: [2, 3] },
18+
nested: {
19+
prop: [
20+
2,
21+
3,
22+
],
23+
},
1224
other: {},
1325
})
1426
return output
15-
}, {
16-
nested: { prop: [1, 2, 3] },
17-
other: {},
18-
}, 'nested.prop')
27+
})
1928
})
20-
2129
it('should drop several elements at the start of the array', () => {
22-
immutaTest((input, path) => {
30+
immutaTest({
31+
nested: {
32+
prop: [
33+
1,
34+
2,
35+
3,
36+
4,
37+
],
38+
},
39+
other: {},
40+
}, ['nested.prop'], (input, path) => {
2341
const output = drop(input, path, 2)
2442
expect(output).toEqual({
25-
nested: { prop: [3, 4] },
43+
nested: {
44+
prop: [
45+
3,
46+
4,
47+
],
48+
},
2649
other: {},
2750
})
2851
return output
29-
}, {
30-
nested: { prop: [1, 2, 3, 4] },
31-
other: {},
32-
}, 'nested.prop')
52+
})
3353
})
34-
3554
it('should replace deep undefined with array', () => {
36-
immutaTest((input, path) => {
55+
immutaTest(undefined, ['nested.prop'], (input, path) => {
3756
const output = drop(input, path)
3857
expect(output).toEqual({ nested: { prop: [] } })
3958
return output
40-
}, undefined, 'nested.prop')
59+
})
4160
})
4261
})
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
/* eslint-env jest */
22
import { dropRight } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('DropRight', () => {
6-
75
it('should drop several elements at the end of the array', () => {
8-
immutaTest((input, path) => {
6+
immutaTest({
7+
nested: {
8+
prop: [
9+
1,
10+
2,
11+
3,
12+
4,
13+
],
14+
},
15+
other: {},
16+
}, ['nested.prop'], (input, path) => {
917
const output = dropRight(input, path, 2)
1018
expect(output).toEqual({
11-
nested: { prop: [1, 2] },
19+
nested: {
20+
prop: [
21+
1,
22+
2,
23+
],
24+
},
1225
other: {},
1326
})
1427
return output
15-
}, {
16-
nested: { prop: [1, 2, 3, 4] },
17-
other: {},
18-
}, 'nested.prop')
28+
})
1929
})
2030
})
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
/* eslint-env jest */
22
import { dropRightWhile } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('DropRightWhile', () => {
6-
75
it('should drop elements > 2 at the end of the array', () => {
8-
immutaTest((input, path) => {
6+
immutaTest({
7+
nested: {
8+
prop: [
9+
1,
10+
2,
11+
3,
12+
4,
13+
],
14+
},
15+
other: {},
16+
}, ['nested.prop'], (input, path) => {
917
const output = dropRightWhile(input, path, v => v > 2)
1018
expect(output).toEqual({
11-
nested: { prop: [1, 2] },
19+
nested: {
20+
prop: [
21+
1,
22+
2,
23+
],
24+
},
1225
other: {},
1326
})
1427
return output
15-
}, {
16-
nested: { prop: [1, 2, 3, 4] },
17-
other: {},
18-
}, 'nested.prop')
28+
})
1929
})
2030
})
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
/* eslint-env jest */
22
import { dropWhile } from 'array'
33
import { immutaTest } from 'test.utils'
4-
54
describe('DropWhile', () => {
6-
75
it('should drop elements < 3 at the beginning of the array', () => {
8-
immutaTest((input, path) => {
6+
immutaTest({
7+
nested: {
8+
prop: [
9+
1,
10+
2,
11+
3,
12+
4,
13+
],
14+
},
15+
other: {},
16+
}, ['nested.prop'], (input, path) => {
917
const output = dropWhile(input, path, v => v < 3)
1018
expect(output).toEqual({
11-
nested: { prop: [3, 4] },
19+
nested: {
20+
prop: [
21+
3,
22+
4,
23+
],
24+
},
1225
other: {},
1326
})
1427
return output
15-
}, {
16-
nested: { prop: [1, 2, 3, 4] },
17-
other: {},
18-
}, 'nested.prop')
28+
})
1929
})
2030
})

0 commit comments

Comments
 (0)