Skip to content

Commit bd82f64

Browse files
authored
refactor: replace lodash with own implementation when possible (#593)
1 parent a93c0c4 commit bd82f64

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"chalk": "^3.0.0",
8787
"css.escape": "^1.5.1",
8888
"dom-accessibility-api": "^0.6.3",
89-
"lodash": "^4.17.15",
89+
"lodash": "^4.17.21",
9090
"redent": "^3.0.0"
9191
},
9292
"devDependencies": {

Diff for: src/to-have-form-values.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import isEqualWith from 'lodash/isEqualWith.js'
2-
import uniq from 'lodash/uniq.js'
1+
import isEqualWith from 'lodash/isEqualWith'
32
import escape from 'css.escape'
43
import {
54
checkHtmlElement,
6-
compareArraysAsSet,
75
getSingleElementValue,
6+
compareArraysAsSet,
87
} from './utils'
98

109
// Returns the combined value of several elements that have the same name
1110
// e.g. radio buttons or groups of checkboxes
1211
function getMultiElementValue(elements) {
13-
const types = uniq(elements.map(element => element.type))
12+
const types = [...new Set(elements.map(element => element.type))]
1413
if (types.length !== 1) {
1514
throw new Error(
1615
'Multiple form elements with the same name must be of the same type',

Diff for: src/to-have-value.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import isEqualWith from 'lodash/isEqualWith.js'
1+
import isEqualWith from 'lodash/isEqualWith'
22
import {
33
checkHtmlElement,
4-
compareArraysAsSet,
54
getMessage,
65
getSingleElementValue,
6+
compareArraysAsSet,
77
} from './utils'
88

99
export function toHaveValue(htmlElement, expectedValue) {

Diff for: src/utils.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import redent from 'redent'
2-
import isEqual from 'lodash/isEqual.js'
32
import {parse} from '@adobe/css-tools'
43

54
class GenericTypeError extends Error {
@@ -212,13 +211,6 @@ function getSingleElementValue(element) {
212211
}
213212
}
214213

215-
function compareArraysAsSet(a, b) {
216-
if (Array.isArray(a) && Array.isArray(b)) {
217-
return isEqual(new Set(a), new Set(b))
218-
}
219-
return undefined
220-
}
221-
222214
function toSentence(
223215
array,
224216
{wordConnector = ', ', lastWordConnector = ' and '} = {},
@@ -228,6 +220,13 @@ function toSentence(
228220
)
229221
}
230222

223+
function compareArraysAsSet(arr1, arr2) {
224+
if (Array.isArray(arr1) && Array.isArray(arr2)) {
225+
return [...new Set(arr1)].every(v => new Set(arr2).has(v))
226+
}
227+
return undefined
228+
}
229+
231230
export {
232231
HtmlElementTypeError,
233232
NodeTypeError,
@@ -240,6 +239,6 @@ export {
240239
normalize,
241240
getTag,
242241
getSingleElementValue,
243-
compareArraysAsSet,
244242
toSentence,
243+
compareArraysAsSet,
245244
}

0 commit comments

Comments
 (0)