Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -84,7 +84,6 @@
"aria-query": "^5.0.0",
"css.escape": "^1.5.1",
"dom-accessibility-api": "^0.6.3",
"lodash": "^4.17.21",
"picocolors": "^1.1.1",
"redent": "^3.0.0"
},
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,
compareAsSet,
getSingleElementValue,
compareArraysAsSet,
} 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),
compareAsSet(formValues[name], expectedValue),
),
message: () => {
const to = this.isNot ? 'not to' : 'to'
Expand Down
7 changes: 3 additions & 4 deletions src/to-have-selection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import isEqualWith from 'lodash/isEqualWith.js'
import {checkHtmlElement, compareArraysAsSet, getMessage} from './utils'
import {checkHtmlElement, compareAsSet, getMessage} from './utils'

/**
* Returns the selection from the element.
*
*
* @param element {HTMLElement} The element to get the selection from.
* @returns {String} The selection.
*/
Expand Down Expand Up @@ -92,7 +91,7 @@ export function toHaveSelection(htmlElement, expectedSelection) {

return {
pass: expectsSelection
? isEqualWith(receivedSelection, expectedSelection, compareArraysAsSet)
? compareAsSet(receivedSelection, expectedSelection)
: Boolean(receivedSelection),
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,
compareAsSet,
getMessage,
getSingleElementValue,
compareArraysAsSet,
} 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)
? compareAsSet(receivedValue, expectedValue)
: Boolean(receivedValue),
message: () => {
const to = this.isNot ? 'not to' : 'to'
Expand Down
10 changes: 5 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ 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 compareAsSet(val1, val2) {
if (Array.isArray(val1) && Array.isArray(val2)) {
return [...new Set(val1)].every(v => new Set(val2).has(v))
}
return undefined
return val1 === val2
}

export {
Expand All @@ -250,5 +250,5 @@ export {
getTag,
getSingleElementValue,
toSentence,
compareArraysAsSet,
compareAsSet,
}