diff --git a/packages/enzyme/package.json b/packages/enzyme/package.json index f305bd196..a98690f2f 100644 --- a/packages/enzyme/package.json +++ b/packages/enzyme/package.json @@ -43,7 +43,8 @@ "is-number-object": "^1.0.3", "is-string": "^1.0.4", "is-subset": "^0.1.1", - "lodash": "^4.17.4", + "lodash.escape": "^4.0.1", + "lodash.isequal": "^4.5.0", "object-inspect": "^1.6.0", "object-is": "^1.0.1", "object.assign": "^4.1.0", diff --git a/packages/enzyme/src/Debug.js b/packages/enzyme/src/Debug.js index 93d017024..126d4735c 100644 --- a/packages/enzyme/src/Debug.js +++ b/packages/enzyme/src/Debug.js @@ -1,6 +1,4 @@ -import without from 'lodash/without'; -import escape from 'lodash/escape'; -import compact from 'lodash/compact'; +import escape from 'lodash.escape'; import functionName from 'function.prototype.name'; import isString from 'is-string'; import isNumber from 'is-number-object'; @@ -59,7 +57,7 @@ function propString(prop, options) { function propsString(node, options) { const props = propsOfNode(node); - const keys = without(Object.keys(props), 'children'); + const keys = Object.keys(props).filter(x => x !== 'children'); return keys.map(key => `${key}=${propString(props[key], options)}`).join(' '); } @@ -77,7 +75,9 @@ export function debugNode(node, indentLength = 2, options = {}) { } if (!node) return ''; - const childrenStrs = compact(childrenOfNode(node).map(n => debugNode(n, indentLength, options))); + const childrenStrs = childrenOfNode(node) + .map(n => debugNode(n, indentLength, options)) + .filter(Boolean); const type = typeName(node); const props = options.ignoreProps ? '' : propsString(node, options); diff --git a/packages/enzyme/src/ReactWrapper.js b/packages/enzyme/src/ReactWrapper.js index d40e8c17a..02b56b59b 100644 --- a/packages/enzyme/src/ReactWrapper.js +++ b/packages/enzyme/src/ReactWrapper.js @@ -1,6 +1,5 @@ import cheerio from 'cheerio'; import flat from 'array.prototype.flat'; -import compact from 'lodash/compact'; import { containsChildrenSubArray, @@ -57,7 +56,7 @@ function findWhereUnwrapped(wrapper, predicate, filter = treeFilter) { * @returns {ReactWrapper} */ function filterWhereUnwrapped(wrapper, predicate) { - return wrapper.wrap(compact(wrapper.getNodesInternal().filter(predicate))); + return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean)); } function privateSetNodes(wrapper, nodes) { @@ -925,8 +924,7 @@ class ReactWrapper { flatMap(fn) { const nodes = this.getNodesInternal().map((n, i) => fn.call(this, this.wrap(n), i)); const flattened = flat(nodes, 1); - const compacted = compact(flattened); - return this.wrap(compacted); + return this.wrap(flattened.filter(Boolean)); } /** diff --git a/packages/enzyme/src/ShallowWrapper.js b/packages/enzyme/src/ShallowWrapper.js index 4c1801952..1e9e68969 100644 --- a/packages/enzyme/src/ShallowWrapper.js +++ b/packages/enzyme/src/ShallowWrapper.js @@ -1,5 +1,4 @@ import flat from 'array.prototype.flat'; -import compact from 'lodash/compact'; import cheerio from 'cheerio'; import { @@ -61,7 +60,7 @@ function findWhereUnwrapped(wrapper, predicate, filter = treeFilter) { * @returns {ShallowWrapper} */ function filterWhereUnwrapped(wrapper, predicate) { - return wrapper.wrap(compact(wrapper.getNodesInternal().filter(predicate))); + return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean)); } /** @@ -1129,8 +1128,7 @@ class ShallowWrapper { flatMap(fn) { const nodes = this.getNodesInternal().map((n, i) => fn.call(this, this.wrap(n), i)); const flattened = flat(nodes, 1); - const compacted = compact(flattened); - return this.wrap(compacted); + return this.wrap(flattened.filter(Boolean)); } /** diff --git a/packages/enzyme/src/Utils.js b/packages/enzyme/src/Utils.js index 729cecec9..7da31c141 100644 --- a/packages/enzyme/src/Utils.js +++ b/packages/enzyme/src/Utils.js @@ -1,5 +1,5 @@ /* eslint no-use-before-define: 0 */ -import isEqual from 'lodash/isEqual'; +import isEqual from 'lodash.isequal'; import is from 'object-is'; import entries from 'object.entries'; import functionName from 'function.prototype.name'; diff --git a/packages/enzyme/src/selectors.js b/packages/enzyme/src/selectors.js index dc239d221..a84e8f147 100644 --- a/packages/enzyme/src/selectors.js +++ b/packages/enzyme/src/selectors.js @@ -1,8 +1,6 @@ import { createParser } from 'rst-selector-parser'; import values from 'object.values'; -import isEmpty from 'lodash/isEmpty'; import flat from 'array.prototype.flat'; -import unique from 'lodash/uniq'; import is from 'object-is'; import has from 'has'; import { @@ -42,6 +40,10 @@ const PREFIX_ATTRIBUTE_OPERATOR = '^='; const SUFFIX_ATTRIBUTE_OPERATOR = '$='; const SUBSTRING_ATTRIBUTE_OPERATOR = '*='; +function unique(arr) { + return [...new Set(arr)]; +} + /** * Calls reduce on a array of nodes with the passed * function, returning only unique results. @@ -260,7 +262,7 @@ export function buildPredicate(selector) { } // If the selector is an non-empty object, treat the keys/values as props if (typeof selector === 'object') { - if (!Array.isArray(selector) && selector !== null && !isEmpty(selector)) { + if (!Array.isArray(selector) && selector !== null && Object.keys(selector).length > 0) { const hasUndefinedValues = values(selector).some(value => typeof value === 'undefined'); if (hasUndefinedValues) { throw new TypeError('Enzyme::Props can’t have `undefined` values. Try using ‘findWhere()’ instead.');