Comparing version 3.4.4 to 3.5.0
@@ -15,14 +15,6 @@ 'use strict'; | ||
var _without = require('lodash/without'); | ||
var _lodash = require('lodash.escape'); | ||
var _without2 = _interopRequireDefault(_without); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _escape = require('lodash/escape'); | ||
var _escape2 = _interopRequireDefault(_escape); | ||
var _compact = require('lodash/compact'); | ||
var _compact2 = _interopRequireDefault(_compact); | ||
var _functionPrototype = require('function.prototype.name'); | ||
@@ -105,3 +97,5 @@ | ||
var props = (0, _RSTTraversal.propsOfNode)(node); | ||
var keys = (0, _without2['default'])(Object.keys(props), 'children'); | ||
var keys = Object.keys(props).filter(function (x) { | ||
return x !== 'children'; | ||
}); | ||
return keys.map(function (key) { | ||
@@ -122,3 +116,3 @@ return String(key) + '=' + String(propString(props[key], options)); | ||
if (typeof node === 'string' || typeof node === 'number') return (0, _escape2['default'])(node); | ||
if (typeof node === 'string' || typeof node === 'number') return (0, _lodash2['default'])(node); | ||
if (typeof node === 'function') { | ||
@@ -130,5 +124,5 @@ var name = (0, _functionPrototype2['default'])(node); | ||
var childrenStrs = (0, _compact2['default'])((0, _RSTTraversal.childrenOfNode)(node).map(function (n) { | ||
var childrenStrs = (0, _RSTTraversal.childrenOfNode)(node).map(function (n) { | ||
return debugNode(n, indentLength, options); | ||
})); | ||
}).filter(Boolean); | ||
var type = typeName(node); | ||
@@ -135,0 +129,0 @@ |
@@ -23,6 +23,2 @@ 'use strict'; | ||
var _compact = require('lodash/compact'); | ||
var _compact2 = _interopRequireDefault(_compact); | ||
var _Utils = require('./Utils'); | ||
@@ -46,4 +42,2 @@ | ||
var noop = function noop() {}; | ||
var NODE = (0, _Utils.sym)('__node__'); | ||
@@ -82,3 +76,3 @@ var NODES = (0, _Utils.sym)('__nodes__'); | ||
function filterWhereUnwrapped(wrapper, predicate) { | ||
return wrapper.wrap((0, _compact2['default'])(wrapper.getNodesInternal().filter(predicate))); | ||
return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean)); | ||
} | ||
@@ -116,4 +110,9 @@ | ||
if (!root) { | ||
var adapter = (0, _getAdapter2['default'])(options); | ||
if (!adapter.isValidElement(nodes)) { | ||
throw new TypeError('ReactWrapper can only wrap valid elements'); | ||
} | ||
(0, _Utils.privateSet)(this, UNRENDERED, nodes); | ||
var renderer = (0, _getAdapter2['default'])(options).createRenderer((0, _object2['default'])({ mode: 'mount' }, options)); | ||
var renderer = adapter.createRenderer((0, _object2['default'])({ mode: 'mount' }, options)); | ||
(0, _Utils.privateSet)(this, RENDERER, renderer); | ||
@@ -408,3 +407,3 @@ renderer.render(nodes, options.context); | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop; | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
@@ -414,3 +413,3 @@ if (this[ROOT] !== this) { | ||
} | ||
if (typeof callback !== 'function') { | ||
if (arguments.length > 1 && typeof callback !== 'function') { | ||
throw new TypeError('ReactWrapper::setProps() expects a function as its second argument'); | ||
@@ -422,3 +421,5 @@ } | ||
_this3.update(); | ||
callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
@@ -456,3 +457,3 @@ return this; | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ReactWrapper::setState() can only be called on class components'); | ||
@@ -965,3 +966,3 @@ } | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ReactWrapper::state() can only be called on class components'); | ||
@@ -1448,4 +1449,3 @@ } | ||
var flattened = (0, _arrayPrototype2['default'])(nodes, 1); | ||
var compacted = (0, _compact2['default'])(flattened); | ||
return this.wrap(compacted); | ||
return this.wrap(flattened.filter(Boolean)); | ||
} | ||
@@ -1452,0 +1452,0 @@ |
@@ -21,6 +21,2 @@ 'use strict'; | ||
var _isEmpty = require('lodash/isEmpty'); | ||
var _isEmpty2 = _interopRequireDefault(_isEmpty); | ||
var _arrayPrototype = require('array.prototype.flat'); | ||
@@ -30,6 +26,2 @@ | ||
var _uniq = require('lodash/uniq'); | ||
var _uniq2 = _interopRequireDefault(_uniq); | ||
var _objectIs = require('object-is'); | ||
@@ -53,2 +45,4 @@ | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
// our CSS selector parser instance | ||
@@ -81,2 +75,6 @@ var parser = (0, _rstSelectorParser.createParser)(); | ||
function unique(arr) { | ||
return [].concat(_toConsumableArray(new Set(arr))); | ||
} | ||
/** | ||
@@ -89,3 +87,3 @@ * Calls reduce on a array of nodes with the passed | ||
function uniqueReduce(fn, nodes) { | ||
return (0, _uniq2['default'])(nodes.reduce(fn, [])); | ||
return unique(nodes.reduce(fn, [])); | ||
} | ||
@@ -320,3 +318,3 @@ | ||
if ((typeof selector === 'undefined' ? 'undefined' : _typeof(selector)) === 'object') { | ||
if (!Array.isArray(selector) && selector !== null && !(0, _isEmpty2['default'])(selector)) { | ||
if (!Array.isArray(selector) && selector !== null && Object.keys(selector).length > 0) { | ||
var hasUndefinedValues = (0, _object2['default'])(selector).some(function (value) { | ||
@@ -492,3 +490,3 @@ return typeof value === 'undefined'; | ||
}); | ||
return (0, _uniq2['default'])((0, _arrayPrototype2['default'])(results, 1)); | ||
return unique((0, _arrayPrototype2['default'])(results, 1)); | ||
} |
@@ -17,5 +17,5 @@ 'use strict'; | ||
var _compact = require('lodash/compact'); | ||
var _lodash = require('lodash.isequal'); | ||
var _compact2 = _interopRequireDefault(_compact); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
@@ -42,6 +42,6 @@ var _cheerio = require('cheerio'); | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var noop = function noop() {}; | ||
var NODE = (0, _Utils.sym)('__node__'); | ||
@@ -80,3 +80,3 @@ var NODES = (0, _Utils.sym)('__nodes__'); | ||
function filterWhereUnwrapped(wrapper, predicate) { | ||
return wrapper.wrap((0, _compact2['default'])(wrapper.getNodesInternal().filter(predicate))); | ||
return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean)); | ||
} | ||
@@ -132,3 +132,5 @@ | ||
return (0, _object2['default'])({}, lifecycles, componentDidUpdate && { componentDidUpdate: componentDidUpdate }); | ||
return (0, _object2['default'])({}, lifecycles, { | ||
setState: (0, _object2['default'])({}, lifecycles.setState) | ||
}, componentDidUpdate && { componentDidUpdate: componentDidUpdate }); | ||
} | ||
@@ -158,2 +160,10 @@ | ||
function pureComponentShouldComponentUpdate(prevProps, props, prevState, state) { | ||
return !(0, _lodash2['default'])(prevProps, props) || !(0, _lodash2['default'])(prevState, state); | ||
} | ||
function isPureComponent(instance) { | ||
return instance && instance.isPureReactComponent; | ||
} | ||
/** | ||
@@ -179,2 +189,6 @@ * @class ShallowWrapper | ||
if (!root) { | ||
if (!adapter.isValidElement(nodes)) { | ||
throw new TypeError('ShallowWrapper can only wrap valid elements'); | ||
} | ||
(0, _Utils.privateSet)(this, ROOT, this); | ||
@@ -195,4 +209,5 @@ (0, _Utils.privateSet)(this, UNRENDERED, nodes); | ||
(0, _Utils.privateSet)(instance, SET_STATE, instance.setState); | ||
instance.setState = function () { | ||
return _this.setState.apply(_this, arguments); | ||
instance.setState = function (updater) { | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return _this.setState.apply(_this, _toConsumableArray(callback == null ? [updater] : [updater, callback])); | ||
}; | ||
@@ -412,2 +427,4 @@ } | ||
spy = (0, _Utils.spyMethod)(instance, 'shouldComponentUpdate'); | ||
} else if (isPureComponent(instance)) { | ||
shouldRender = pureComponentShouldComponentUpdate(prevProps, props, state, instance.state); | ||
} | ||
@@ -439,3 +456,3 @@ if (props) _this2[UNRENDERED] = (0, _Utils.cloneElement)(adapter, _this2[UNRENDERED], props); | ||
// If it doesn't need to rerender, update only its props. | ||
} else if (props) { | ||
} else if (!(0, _lodash2['default'])(props, instance.props)) { | ||
instance.props = (Object.freeze || Object)((0, _object2['default'])({}, instance.props, props)); | ||
@@ -472,3 +489,3 @@ } | ||
function setProps(props) { | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop; | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
@@ -478,7 +495,9 @@ if (this[ROOT] !== this) { | ||
} | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('ShallowWrapper::setProps() expects a function as its second argument'); | ||
if (arguments.length > 1 && typeof callback !== 'function') { | ||
throw new TypeError('ReactWrapper::setProps() expects a function as its second argument'); | ||
} | ||
this.rerender(props); | ||
callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
return this; | ||
@@ -515,3 +534,3 @@ } | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ShallowWrapper::setState() can only be called on class components'); | ||
@@ -522,2 +541,3 @@ } | ||
} | ||
this.single('setState', function () { | ||
@@ -533,2 +553,9 @@ (0, _Utils.withSetStateAllowed)(function () { | ||
var prevContext = instance.context; | ||
var statePayload = typeof state === 'function' ? state.call(instance, prevState, prevProps) : state; | ||
// returning null or undefined prevents the update in React 16+ | ||
// https://github.com/facebook/react/pull/12756 | ||
var maybeHasUpdate = !lifecycles.setState.skipsComponentDidUpdateOnNullish || statePayload != null; | ||
// When shouldComponentUpdate returns false we shouldn't call componentDidUpdate. | ||
@@ -540,2 +567,4 @@ // so we spy shouldComponentUpdate to get the result. | ||
spy = (0, _Utils.spyMethod)(instance, 'shouldComponentUpdate'); | ||
} else if (isPureComponent(instance)) { | ||
shouldRender = pureComponentShouldComponentUpdate(prevProps, instance.props, prevState, statePayload); | ||
} | ||
@@ -545,5 +574,5 @@ // We don't pass the setState callback here | ||
if (instance[SET_STATE]) { | ||
instance[SET_STATE](state); | ||
instance[SET_STATE](statePayload); | ||
} else { | ||
instance.setState(state); | ||
instance.setState(statePayload); | ||
} | ||
@@ -554,3 +583,3 @@ if (spy) { | ||
} | ||
if (shouldRender && !_this3[OPTIONS].disableLifecycleMethods && lifecycles.componentDidUpdate && lifecycles.componentDidUpdate.onSetState && instance) { | ||
if (maybeHasUpdate && shouldRender && !_this3[OPTIONS].disableLifecycleMethods && lifecycles.componentDidUpdate && lifecycles.componentDidUpdate.onSetState && instance) { | ||
if (lifecycles.getSnapshotBeforeUpdate && typeof instance.getSnapshotBeforeUpdate === 'function') { | ||
@@ -1087,3 +1116,3 @@ var snapshot = instance.getSnapshotBeforeUpdate(prevProps, prevState); | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ShallowWrapper::state() can only be called on class components'); | ||
@@ -1594,4 +1623,3 @@ } | ||
var flattened = (0, _arrayPrototype2['default'])(nodes, 1); | ||
var compacted = (0, _compact2['default'])(flattened); | ||
return this.wrap(compacted); | ||
return this.wrap(flattened.filter(Boolean)); | ||
} | ||
@@ -1598,0 +1626,0 @@ |
@@ -36,5 +36,5 @@ 'use strict'; | ||
var _isEqual = require('lodash/isEqual'); | ||
var _lodash = require('lodash.isequal'); | ||
var _isEqual2 = _interopRequireDefault(_isEqual); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
@@ -197,3 +197,3 @@ var _objectIs = require('object-is'); | ||
} else if (_typeof(right[prop]) === _typeof(left[prop]) && _typeof(left[prop]) === 'object') { | ||
if (!(0, _isEqual2['default'])(left[prop], right[prop])) return false; | ||
if (!(0, _lodash2['default'])(left[prop], right[prop])) return false; | ||
} else { | ||
@@ -200,0 +200,0 @@ return false; |
{ | ||
"name": "enzyme", | ||
"version": "3.4.4", | ||
"version": "3.5.0", | ||
"description": "JavaScript Testing utilities for React", | ||
@@ -46,3 +46,4 @@ "homepage": "http://airbnb.io/enzyme/", | ||
"is-subset": "^0.1.1", | ||
"lodash": "^4.17.4", | ||
"lodash.escape": "^4.0.1", | ||
"lodash.isequal": "^4.5.0", | ||
"object-inspect": "^1.6.0", | ||
@@ -60,3 +61,3 @@ "object-is": "^1.0.1", | ||
"babel-preset-airbnb": "^2.5.3", | ||
"eslint": "^5.3.0", | ||
"eslint": "^5.4.0", | ||
"eslint-config-airbnb": "^17.1.0", | ||
@@ -63,0 +64,0 @@ "eslint-plugin-import": "^2.14.0", |
@@ -129,3 +129,3 @@ Enzyme | ||
const wrapper = shallow(<MyComponent />); | ||
expect(wrapper.find(Foo)).to.have.length(3); | ||
expect(wrapper.find(Foo)).to.have.lengthOf(3); | ||
}); | ||
@@ -135,3 +135,3 @@ | ||
const wrapper = shallow(<MyComponent />); | ||
expect(wrapper.find('.icon-star')).to.have.length(1); | ||
expect(wrapper.find('.icon-star')).to.have.lengthOf(1); | ||
}); | ||
@@ -138,0 +138,0 @@ |
@@ -1,4 +0,2 @@ | ||
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'; | ||
@@ -62,3 +60,3 @@ import isString from 'is-string'; | ||
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(' '); | ||
@@ -81,3 +79,5 @@ } | ||
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); | ||
@@ -84,0 +84,0 @@ |
import cheerio from 'cheerio'; | ||
import flat from 'array.prototype.flat'; | ||
import compact from 'lodash/compact'; | ||
@@ -29,4 +28,2 @@ import { | ||
const noop = () => {}; | ||
const NODE = sym('__node__'); | ||
@@ -61,3 +58,3 @@ const NODES = sym('__nodes__'); | ||
function filterWhereUnwrapped(wrapper, predicate) { | ||
return wrapper.wrap(compact(wrapper.getNodesInternal().filter(predicate))); | ||
return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean)); | ||
} | ||
@@ -90,4 +87,9 @@ | ||
if (!root) { | ||
const adapter = getAdapter(options); | ||
if (!adapter.isValidElement(nodes)) { | ||
throw new TypeError('ReactWrapper can only wrap valid elements'); | ||
} | ||
privateSet(this, UNRENDERED, nodes); | ||
const renderer = getAdapter(options).createRenderer({ mode: 'mount', ...options }); | ||
const renderer = adapter.createRenderer({ mode: 'mount', ...options }); | ||
privateSet(this, RENDERER, renderer); | ||
@@ -275,7 +277,7 @@ renderer.render(nodes, options.context); | ||
*/ | ||
setProps(props, callback = noop) { | ||
setProps(props, callback = undefined) { | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::setProps() can only be called on the root'); | ||
} | ||
if (typeof callback !== 'function') { | ||
if (arguments.length > 1 && typeof callback !== 'function') { | ||
throw new TypeError('ReactWrapper::setProps() expects a function as its second argument'); | ||
@@ -287,3 +289,5 @@ } | ||
this.update(); | ||
callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
@@ -310,3 +314,3 @@ return this; | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ReactWrapper::setState() can only be called on class components'); | ||
@@ -642,3 +646,3 @@ } | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ReactWrapper::state() can only be called on class components'); | ||
@@ -930,4 +934,3 @@ } | ||
const flattened = flat(nodes, 1); | ||
const compacted = compact(flattened); | ||
return this.wrap(compacted); | ||
return this.wrap(flattened.filter(Boolean)); | ||
} | ||
@@ -934,0 +937,0 @@ |
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'; | ||
@@ -45,2 +43,6 @@ import has from 'has'; | ||
function unique(arr) { | ||
return [...new Set(arr)]; | ||
} | ||
/** | ||
@@ -264,3 +266,3 @@ * Calls reduce on a array of nodes with the passed | ||
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'); | ||
@@ -267,0 +269,0 @@ if (hasUndefinedValues) { |
import flat from 'array.prototype.flat'; | ||
import compact from 'lodash/compact'; | ||
import isEqual from 'lodash.isequal'; | ||
import cheerio from 'cheerio'; | ||
@@ -33,4 +33,2 @@ | ||
const noop = () => {}; | ||
const NODE = sym('__node__'); | ||
@@ -65,3 +63,3 @@ const NODES = sym('__nodes__'); | ||
function filterWhereUnwrapped(wrapper, predicate) { | ||
return wrapper.wrap(compact(wrapper.getNodesInternal().filter(predicate))); | ||
return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean)); | ||
} | ||
@@ -136,2 +134,5 @@ | ||
...lifecycles, | ||
setState: { | ||
...lifecycles.setState, | ||
}, | ||
...(componentDidUpdate && { componentDidUpdate }), | ||
@@ -163,2 +164,10 @@ }; | ||
function pureComponentShouldComponentUpdate(prevProps, props, prevState, state) { | ||
return !isEqual(prevProps, props) || !isEqual(prevState, state); | ||
} | ||
function isPureComponent(instance) { | ||
return instance && instance.isPureReactComponent; | ||
} | ||
/** | ||
@@ -177,2 +186,6 @@ * @class ShallowWrapper | ||
if (!root) { | ||
if (!adapter.isValidElement(nodes)) { | ||
throw new TypeError('ShallowWrapper can only wrap valid elements'); | ||
} | ||
privateSet(this, ROOT, this); | ||
@@ -192,3 +205,5 @@ privateSet(this, UNRENDERED, nodes); | ||
privateSet(instance, SET_STATE, instance.setState); | ||
instance.setState = (...args) => this.setState(...args); | ||
instance.setState = (updater, callback = undefined) => this.setState( | ||
...(callback == null ? [updater] : [updater, callback]), | ||
); | ||
} | ||
@@ -344,2 +359,9 @@ | ||
spy = spyMethod(instance, 'shouldComponentUpdate'); | ||
} else if (isPureComponent(instance)) { | ||
shouldRender = pureComponentShouldComponentUpdate( | ||
prevProps, | ||
props, | ||
state, | ||
instance.state, | ||
); | ||
} | ||
@@ -381,3 +403,3 @@ if (props) this[UNRENDERED] = cloneElement(adapter, this[UNRENDERED], props); | ||
// If it doesn't need to rerender, update only its props. | ||
} else if (props) { | ||
} else if (!isEqual(props, instance.props)) { | ||
instance.props = (Object.freeze || Object)({ ...instance.props, ...props }); | ||
@@ -406,11 +428,13 @@ } | ||
*/ | ||
setProps(props, callback = noop) { | ||
setProps(props, callback = undefined) { | ||
if (this[ROOT] !== this) { | ||
throw new Error('ShallowWrapper::setProps() can only be called on the root'); | ||
} | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('ShallowWrapper::setProps() expects a function as its second argument'); | ||
if (arguments.length > 1 && typeof callback !== 'function') { | ||
throw new TypeError('ReactWrapper::setProps() expects a function as its second argument'); | ||
} | ||
this.rerender(props); | ||
callback(); | ||
if (callback) { | ||
callback(); | ||
} | ||
return this; | ||
@@ -436,3 +460,3 @@ } | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ShallowWrapper::setState() can only be called on class components'); | ||
@@ -443,2 +467,3 @@ } | ||
} | ||
this.single('setState', () => { | ||
@@ -454,2 +479,12 @@ withSetStateAllowed(() => { | ||
const prevContext = instance.context; | ||
const statePayload = typeof state === 'function' | ||
? state.call(instance, prevState, prevProps) | ||
: state; | ||
// returning null or undefined prevents the update in React 16+ | ||
// https://github.com/facebook/react/pull/12756 | ||
const maybeHasUpdate = !lifecycles.setState.skipsComponentDidUpdateOnNullish | ||
|| statePayload != null; | ||
// When shouldComponentUpdate returns false we shouldn't call componentDidUpdate. | ||
@@ -467,2 +502,9 @@ // so we spy shouldComponentUpdate to get the result. | ||
spy = spyMethod(instance, 'shouldComponentUpdate'); | ||
} else if (isPureComponent(instance)) { | ||
shouldRender = pureComponentShouldComponentUpdate( | ||
prevProps, | ||
instance.props, | ||
prevState, | ||
statePayload, | ||
); | ||
} | ||
@@ -472,5 +514,5 @@ // We don't pass the setState callback here | ||
if (instance[SET_STATE]) { | ||
instance[SET_STATE](state); | ||
instance[SET_STATE](statePayload); | ||
} else { | ||
instance.setState(state); | ||
instance.setState(statePayload); | ||
} | ||
@@ -482,3 +524,4 @@ if (spy) { | ||
if ( | ||
shouldRender | ||
maybeHasUpdate | ||
&& shouldRender | ||
&& !this[OPTIONS].disableLifecycleMethods | ||
@@ -839,3 +882,3 @@ && lifecycles.componentDidUpdate | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') { | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
throw new Error('ShallowWrapper::state() can only be called on class components'); | ||
@@ -1144,4 +1187,3 @@ } | ||
const flattened = flat(nodes, 1); | ||
const compacted = compact(flattened); | ||
return this.wrap(compacted); | ||
return this.wrap(flattened.filter(Boolean)); | ||
} | ||
@@ -1148,0 +1190,0 @@ |
/* eslint no-use-before-define: 0 */ | ||
import isEqual from 'lodash/isEqual'; | ||
import isEqual from 'lodash.isequal'; | ||
import is from 'object-is'; | ||
@@ -4,0 +4,0 @@ import entries from 'object.entries'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284482
7748
18
+ Addedlodash.escape@^4.0.1
+ Addedlodash.isequal@^4.5.0
+ Addedlodash.escape@4.0.1(transitive)
+ Addedlodash.isequal@4.5.0(transitive)
- Removedlodash@^4.17.4
- Removedlodash@4.17.21(transitive)