Skip to content

Commit d4ede3e

Browse files
committed
refactor: drop lodash entirely
1 parent 0402f1f commit d4ede3e

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"aria-query": "^5.0.0",
8585
"css.escape": "^1.5.1",
8686
"dom-accessibility-api": "^0.6.3",
87-
"es-toolkit": "^1.39.8",
8887
"picocolors": "^1.1.1",
8988
"redent": "^3.0.0"
9089
},

src/to-have-form-values.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {isEqualWith} from 'es-toolkit'
21
import escape from 'css.escape'
32
import {
43
checkHtmlElement,
4+
compareAsSet,
55
getSingleElementValue,
6-
compareArraysAsSet,
76
} from './utils'
87

98
// Returns the combined value of several elements that have the same name
@@ -69,7 +68,7 @@ export function toHaveFormValues(formElement, expectedValues) {
6968
const formValues = getAllFormValues(formElement)
7069
return {
7170
pass: Object.entries(expectedValues).every(([name, expectedValue]) =>
72-
isEqualWith(formValues[name], expectedValue, compareArraysAsSet),
71+
compareAsSet(formValues[name], expectedValue),
7372
),
7473
message: () => {
7574
const to = this.isNot ? 'not to' : 'to'

src/to-have-selection.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {isEqualWith} from 'es-toolkit'
2-
import {checkHtmlElement, compareArraysAsSet, getMessage} from './utils'
1+
import {checkHtmlElement, compareAsSet, getMessage} from './utils'
32

43
/**
54
* Returns the selection from the element.
@@ -92,7 +91,7 @@ export function toHaveSelection(htmlElement, expectedSelection) {
9291

9392
return {
9493
pass: expectsSelection
95-
? isEqualWith(receivedSelection, expectedSelection, compareArraysAsSet)
94+
? compareAsSet(receivedSelection, expectedSelection)
9695
: Boolean(receivedSelection),
9796
message: () => {
9897
const to = this.isNot ? 'not to' : 'to'

src/to-have-value.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {isEqualWith} from 'es-toolkit'
21
import {
32
checkHtmlElement,
3+
compareAsSet,
44
getMessage,
55
getSingleElementValue,
6-
compareArraysAsSet,
76
} from './utils'
87

98
export function toHaveValue(htmlElement, expectedValue) {
@@ -30,7 +29,7 @@ export function toHaveValue(htmlElement, expectedValue) {
3029

3130
return {
3231
pass: expectsValue
33-
? isEqualWith(receivedValue, expectedValue, compareArraysAsSet)
32+
? compareAsSet(receivedValue, expectedValue)
3433
: Boolean(receivedValue),
3534
message: () => {
3635
const to = this.isNot ? 'not to' : 'to'

src/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ function toSentence(
230230
)
231231
}
232232

233-
function compareArraysAsSet(arr1, arr2) {
234-
if (Array.isArray(arr1) && Array.isArray(arr2)) {
235-
return [...new Set(arr1)].every(v => new Set(arr2).has(v))
233+
function compareAsSet(val1, val2) {
234+
if (Array.isArray(val1) && Array.isArray(val2)) {
235+
return [...new Set(val1)].every(v => new Set(val2).has(v))
236236
}
237-
return undefined
237+
return val1 === val2
238238
}
239239

240240
export {
@@ -250,5 +250,5 @@ export {
250250
getTag,
251251
getSingleElementValue,
252252
toSentence,
253-
compareArraysAsSet,
253+
compareAsSet,
254254
}

0 commit comments

Comments
 (0)