diff --git a/package.json b/package.json index f272177..f63fbb0 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "chalk": "^3.0.0", "css.escape": "^1.5.1", "dom-accessibility-api": "^0.6.3", - "lodash": "^4.17.15", + "lodash": "^4.17.21", "redent": "^3.0.0" }, "devDependencies": { diff --git a/src/to-have-form-values.js b/src/to-have-form-values.js index fe8c890..034f633 100644 --- a/src/to-have-form-values.js +++ b/src/to-have-form-values.js @@ -1,16 +1,15 @@ -import isEqualWith from 'lodash/isEqualWith.js' -import uniq from 'lodash/uniq.js' +import isEqualWith from 'lodash/isEqualWith' import escape from 'css.escape' import { checkHtmlElement, - compareArraysAsSet, getSingleElementValue, + compareArraysAsSet, } from './utils' // Returns the combined value of several elements that have the same name // e.g. radio buttons or groups of checkboxes function getMultiElementValue(elements) { - const types = uniq(elements.map(element => element.type)) + const types = [...new Set(elements.map(element => element.type))] if (types.length !== 1) { throw new Error( 'Multiple form elements with the same name must be of the same type', diff --git a/src/to-have-value.js b/src/to-have-value.js index da79e41..bbd3c46 100644 --- a/src/to-have-value.js +++ b/src/to-have-value.js @@ -1,9 +1,9 @@ -import isEqualWith from 'lodash/isEqualWith.js' +import isEqualWith from 'lodash/isEqualWith' import { checkHtmlElement, - compareArraysAsSet, getMessage, getSingleElementValue, + compareArraysAsSet, } from './utils' export function toHaveValue(htmlElement, expectedValue) { diff --git a/src/utils.js b/src/utils.js index 903f24c..ee8e484 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,4 @@ import redent from 'redent' -import isEqual from 'lodash/isEqual.js' import {parse} from '@adobe/css-tools' class GenericTypeError extends Error { @@ -212,13 +211,6 @@ function getSingleElementValue(element) { } } -function compareArraysAsSet(a, b) { - if (Array.isArray(a) && Array.isArray(b)) { - return isEqual(new Set(a), new Set(b)) - } - return undefined -} - function toSentence( array, {wordConnector = ', ', lastWordConnector = ' and '} = {}, @@ -228,6 +220,13 @@ function toSentence( ) } +function compareArraysAsSet(arr1, arr2) { + if (Array.isArray(arr1) && Array.isArray(arr2)) { + return [...new Set(arr1)].every(v => new Set(arr2).has(v)) + } + return undefined +} + export { HtmlElementTypeError, NodeTypeError, @@ -240,6 +239,6 @@ export { normalize, getTag, getSingleElementValue, - compareArraysAsSet, toSentence, + compareArraysAsSet, }