Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"chalk": "^3.0.0",
"css.escape": "^1.5.1",
"dom-accessibility-api": "^0.6.3",
"lodash": "^4.17.21",
"redent": "^3.0.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions src/to-have-form-values.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import isEqualWith from 'lodash/isEqualWith.js'
import escape from 'css.escape'
import {
checkHtmlElement,
getSingleElementValue,
compareArraysAsSet,
compare,
} from './utils'

// Returns the combined value of several elements that have the same name
Expand Down Expand Up @@ -69,7 +68,7 @@ export function toHaveFormValues(formElement, expectedValues) {
const formValues = getAllFormValues(formElement)
return {
pass: Object.entries(expectedValues).every(([name, expectedValue]) =>
isEqualWith(formValues[name], expectedValue, compareArraysAsSet),
compare(formValues[name], expectedValue),
),
message: () => {
const to = this.isNot ? 'not to' : 'to'
Expand Down
5 changes: 2 additions & 3 deletions src/to-have-value.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import isEqualWith from 'lodash/isEqualWith.js'
import {
checkHtmlElement,
getMessage,
getSingleElementValue,
compareArraysAsSet,
compare,
} from './utils'

export function toHaveValue(htmlElement, expectedValue) {
Expand All @@ -30,7 +29,7 @@ export function toHaveValue(htmlElement, expectedValue) {

return {
pass: expectsValue
? isEqualWith(receivedValue, expectedValue, compareArraysAsSet)
? compare(receivedValue, expectedValue)
: Boolean(receivedValue),
message: () => {
const to = this.isNot ? 'not to' : 'to'
Expand Down
17 changes: 12 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,18 @@ function toSentence(
)
}

function compareArraysAsSet(arr1, arr2) {
if (Array.isArray(arr1) && Array.isArray(arr2)) {
return [...new Set(arr1)].every(v => new Set(arr2).has(v))
function compareArrays(arr1, arr2) {
return [...new Set(arr1)].every(v => new Set(arr2).has(v));
}

function compare(val1, val2) {
if (val1 === val2) {
return true
}
if (Array.isArray(val1) && Array.isArray(val2)) {
return compareArrays(val1, val2)
}
return undefined
return false
}

export {
Expand All @@ -250,5 +257,5 @@ export {
getTag,
getSingleElementValue,
toSentence,
compareArraysAsSet,
compare,
}
Loading