Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove lodash #593

Merged
merged 3 commits into from Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": {
Expand Down
7 changes: 3 additions & 4 deletions 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',
Expand Down
4 changes: 2 additions & 2 deletions 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) {
Expand Down
17 changes: 8 additions & 9 deletions 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 {
Expand Down Expand Up @@ -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 '} = {},
Expand All @@ -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,
Expand All @@ -240,6 +239,6 @@ export {
normalize,
getTag,
getSingleElementValue,
compareArraysAsSet,
toSentence,
compareArraysAsSet,
}