Comparing version 3.6.0 to 3.7.0
@@ -8,2 +8,3 @@ 'use strict'; | ||
exports.merge = merge; | ||
exports.reset = reset; | ||
@@ -31,2 +32,9 @@ var _object = require('object.assign'); | ||
(0, _object2['default'])(configuration, extra); | ||
} | ||
function reset() { | ||
var replacementConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
configuration = {}; | ||
merge(replacementConfig); | ||
} |
@@ -47,2 +47,3 @@ 'use strict'; | ||
var OPTIONS = (0, _Utils.sym)('__options__'); | ||
var ROOT_NODES = (0, _Utils.sym)('__rootNodes__'); | ||
@@ -78,4 +79,14 @@ /** | ||
function getRootNodeInternal(wrapper) { | ||
if (wrapper[ROOT].length !== 1) { | ||
throw new Error('getRootNodeInternal(wrapper) can only be called when wrapper wraps one node'); | ||
} | ||
if (wrapper[ROOT] !== wrapper) { | ||
return wrapper[ROOT_NODES][0]; | ||
} | ||
return wrapper[ROOT][NODE]; | ||
} | ||
function nodeParents(wrapper, node) { | ||
return (0, _RSTTraversal.parentsOfNode)(node, wrapper[ROOT].getNodeInternal()); | ||
return (0, _RSTTraversal.parentsOfNode)(node, getRootNodeInternal(wrapper)); | ||
} | ||
@@ -129,2 +140,3 @@ | ||
privateSetNodes(this, nodes); | ||
(0, _Utils.privateSet)(this, ROOT_NODES, root[NODES]); | ||
} | ||
@@ -196,6 +208,7 @@ (0, _Utils.privateSet)(this, OPTIONS, root ? root[OPTIONS] : options); | ||
function getElement() { | ||
if (this.length !== 1) { | ||
throw new Error('ReactWrapper::getElement() can only be called when wrapping one node'); | ||
} | ||
return (0, _getAdapter2['default'])(this[OPTIONS]).nodeToElement(this[NODE]); | ||
var _this = this; | ||
return this.single('getElement', function () { | ||
return (0, _getAdapter2['default'])(_this[OPTIONS]).nodeToElement(_this[NODE]); | ||
}); | ||
} | ||
@@ -306,6 +319,7 @@ | ||
function instance() { | ||
if (this.length !== 1) { | ||
throw new Error('ReactWrapper::instance() can only be called on single nodes'); | ||
} | ||
return this[NODE].instance; | ||
var _this2 = this; | ||
return this.single('instance', function () { | ||
return _this2[NODE].instance; | ||
}); | ||
} | ||
@@ -320,3 +334,3 @@ | ||
* | ||
* NOTE: can only be called on a wrapper instance that is also the root instance. | ||
* NOTE: no matter what instance this is called on, it will always update the root. | ||
* | ||
@@ -330,4 +344,5 @@ * @returns {ReactWrapper} | ||
function update() { | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::update() can only be called on the root'); | ||
var root = this[ROOT]; | ||
if (this !== root) { | ||
return root.update(); | ||
} | ||
@@ -352,3 +367,3 @@ privateSetNodes(this, this[RENDERER].getNode()); | ||
function unmount() { | ||
var _this = this; | ||
var _this3 = this; | ||
@@ -359,4 +374,4 @@ if (this[ROOT] !== this) { | ||
this.single('unmount', function () { | ||
_this[RENDERER].unmount(); | ||
_this.update(); | ||
_this3[RENDERER].unmount(); | ||
_this3.update(); | ||
}); | ||
@@ -381,3 +396,3 @@ return this; | ||
function mount() { | ||
var _this2 = this; | ||
var _this4 = this; | ||
@@ -388,3 +403,3 @@ if (this[ROOT] !== this) { | ||
this[RENDERER].render(this[UNRENDERED], this[OPTIONS].context, function () { | ||
return _this2.update(); | ||
return _this4.update(); | ||
}); | ||
@@ -416,3 +431,3 @@ return this; | ||
function setProps(props) { | ||
var _this3 = this; | ||
var _this5 = this; | ||
@@ -430,3 +445,3 @@ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
this[RENDERER].render(this[UNRENDERED], null, function () { | ||
_this3.update(); | ||
_this5.update(); | ||
if (callback) { | ||
@@ -460,9 +475,6 @@ callback(); | ||
function setState(state) { | ||
var _this4 = this; | ||
var _this6 = this; | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::setState() can only be called on the root'); | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
@@ -475,6 +487,6 @@ throw new Error('ReactWrapper::setState() can only be called on class components'); | ||
this.instance().setState(state, function () { | ||
_this4.update(); | ||
_this6.update(); | ||
if (callback) { | ||
var adapter = (0, _getAdapter2['default'])(_this4[OPTIONS]); | ||
var instance = _this4.instance(); | ||
var adapter = (0, _getAdapter2['default'])(_this6[OPTIONS]); | ||
var instance = _this6.instance(); | ||
if (adapter.invokeSetStateCallback) { | ||
@@ -507,3 +519,3 @@ adapter.invokeSetStateCallback(instance, callback); | ||
function setContext(context) { | ||
var _this5 = this; | ||
var _this7 = this; | ||
@@ -517,3 +529,3 @@ if (this[ROOT] !== this) { | ||
this[RENDERER].render(this[UNRENDERED], context, function () { | ||
return _this5.update(); | ||
return _this7.update(); | ||
}); | ||
@@ -619,3 +631,3 @@ return this; | ||
function containsAllMatchingElements(nodes) { | ||
var _this6 = this; | ||
var _this8 = this; | ||
@@ -627,3 +639,3 @@ if (!Array.isArray(nodes)) { | ||
return nodes.every(function (node) { | ||
return _this6.containsMatchingElement(node); | ||
return _this8.containsMatchingElement(node); | ||
}); | ||
@@ -658,6 +670,6 @@ } | ||
function containsAnyMatchingElements(nodes) { | ||
var _this7 = this; | ||
var _this9 = this; | ||
return Array.isArray(nodes) && nodes.some(function (node) { | ||
return _this7.containsMatchingElement(node); | ||
return _this9.containsMatchingElement(node); | ||
}); | ||
@@ -686,6 +698,6 @@ } | ||
function equals(node) { | ||
var _this8 = this; | ||
var _this10 = this; | ||
return this.single('equals', function () { | ||
return (0, _Utils.nodeEqual)(_this8.getNodeInternal(), node); | ||
return (0, _Utils.nodeEqual)(_this10.getNodeInternal(), node); | ||
}); | ||
@@ -719,8 +731,8 @@ } | ||
function matchesElement(node) { | ||
var _this9 = this; | ||
var _this11 = this; | ||
return this.single('matchesElement', function () { | ||
var adapter = (0, _getAdapter2['default'])(_this9[OPTIONS]); | ||
var adapter = (0, _getAdapter2['default'])(_this11[OPTIONS]); | ||
var rstNode = adapter.elementToNode(node); | ||
return (0, _Utils.nodeMatches)(rstNode, _this9.getNodeInternal(), function (a, b) { | ||
return (0, _Utils.nodeMatches)(rstNode, _this11.getNodeInternal(), function (a, b) { | ||
return a <= b; | ||
@@ -803,6 +815,6 @@ }); | ||
function filterWhere(predicate) { | ||
var _this10 = this; | ||
var _this12 = this; | ||
return filterWhereUnwrapped(this, function (n) { | ||
return predicate(_this10.wrap(n)); | ||
return predicate(_this12.wrap(n)); | ||
}); | ||
@@ -890,7 +902,7 @@ } | ||
function html() { | ||
var _this11 = this; | ||
var _this13 = this; | ||
return this.single('html', function (n) { | ||
if (n === null) return null; | ||
var adapter = (0, _getAdapter2['default'])(_this11[OPTIONS]); | ||
var adapter = (0, _getAdapter2['default'])(_this13[OPTIONS]); | ||
var node = adapter.nodeToHostNode(n); | ||
@@ -936,3 +948,3 @@ return node === null ? null : node.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g, ''); | ||
function simulate(event) { | ||
var _this12 = this; | ||
var _this14 = this; | ||
@@ -942,5 +954,5 @@ var mock = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return this.single('simulate', function (n) { | ||
_this12[RENDERER].simulateEvent(n, event, mock); | ||
_this12[ROOT].update(); | ||
return _this12; | ||
_this14[RENDERER].simulateEvent(n, event, mock); | ||
_this14[ROOT].update(); | ||
return _this14; | ||
}); | ||
@@ -963,3 +975,3 @@ } | ||
function simulateError(error) { | ||
var _this13 = this; | ||
var _this15 = this; | ||
@@ -975,3 +987,3 @@ if (this[ROOT] === this) { | ||
var renderer = _this13[RENDERER]; | ||
var renderer = _this15[RENDERER]; | ||
if (typeof renderer.simulateError !== 'function') { | ||
@@ -981,7 +993,8 @@ throw new TypeError('your adapter does not support `simulateError`. Try upgrading it!'); | ||
var rootNode = _this13[ROOT].getNodeInternal(); | ||
var nodeHierarchy = [thisNode].concat(nodeParents(_this13, thisNode)); | ||
var rootNode = getRootNodeInternal(_this15); | ||
var nodeHierarchy = [thisNode].concat(nodeParents(_this15, thisNode)); | ||
renderer.simulateError(nodeHierarchy, rootNode, error); | ||
return _this13; | ||
_this15[ROOT].update(); | ||
return _this15; | ||
}); | ||
@@ -1025,7 +1038,4 @@ } | ||
function state(name) { | ||
var _this14 = this; | ||
var _this16 = this; | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::state() can only be called on the root'); | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
@@ -1035,5 +1045,8 @@ throw new Error('ReactWrapper::state() can only be called on class components'); | ||
var _state = this.single('state', function () { | ||
return _this14.instance().state; | ||
return _this16.instance().state; | ||
}); | ||
if (typeof name !== 'undefined') { | ||
if (_state == null) { | ||
throw new TypeError('ReactWrapper::state("' + String(name) + '") requires that `state` not be `null` or `undefined`'); | ||
} | ||
return _state[name]; | ||
@@ -1061,3 +1074,3 @@ } | ||
function context(name) { | ||
var _this15 = this; | ||
var _this17 = this; | ||
@@ -1068,3 +1081,3 @@ if (this[ROOT] !== this) { | ||
var instance = this.single('context', function () { | ||
return _this15.instance(); | ||
return _this17.instance(); | ||
}); | ||
@@ -1117,6 +1130,6 @@ if (instance === null) { | ||
function childAt(index) { | ||
var _this16 = this; | ||
var _this18 = this; | ||
return this.single('childAt', function () { | ||
return _this16.children().at(index); | ||
return _this18.children().at(index); | ||
}); | ||
@@ -1142,8 +1155,8 @@ } | ||
function parents(selector) { | ||
var _this17 = this; | ||
var _this19 = this; | ||
var allParents = this.wrap(this.single('parents', function (n) { | ||
return nodeParents(_this17, n); | ||
})); | ||
return selector ? allParents.filter(selector) : allParents; | ||
return this.single('parents', function (n) { | ||
var allParents = _this19.wrap(nodeParents(_this19, n)); | ||
return selector ? allParents.filter(selector) : allParents; | ||
}); | ||
} | ||
@@ -1306,6 +1319,6 @@ | ||
function forEach(fn) { | ||
var _this18 = this; | ||
var _this20 = this; | ||
this.getNodesInternal().forEach(function (n, i) { | ||
return fn.call(_this18, _this18.wrap(n), i); | ||
return fn.call(_this20, _this20.wrap(n), i); | ||
}); | ||
@@ -1330,6 +1343,6 @@ return this; | ||
function map(fn) { | ||
var _this19 = this; | ||
var _this21 = this; | ||
return this.getNodesInternal().map(function (n, i) { | ||
return fn.call(_this19, _this19.wrap(n), i); | ||
return fn.call(_this21, _this21.wrap(n), i); | ||
}); | ||
@@ -1354,3 +1367,3 @@ } | ||
function reduce(fn) { | ||
var _this20 = this; | ||
var _this22 = this; | ||
@@ -1361,7 +1374,7 @@ var initialValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return this.getNodesInternal().reduce(function (accum, n, i) { | ||
return fn.call(_this20, accum, _this20.wrap(n), i); | ||
return fn.call(_this22, accum, _this22.wrap(n), i); | ||
}, initialValue); | ||
} | ||
return this.getNodesInternal().reduce(function (accum, n, i) { | ||
return fn.call(_this20, i === 1 ? _this20.wrap(accum) : accum, _this20.wrap(n), i); | ||
return fn.call(_this22, i === 1 ? _this22.wrap(accum) : accum, _this22.wrap(n), i); | ||
}); | ||
@@ -1386,3 +1399,3 @@ } | ||
function reduceRight(fn) { | ||
var _this21 = this; | ||
var _this23 = this; | ||
@@ -1393,7 +1406,7 @@ var initialValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return this.getNodesInternal().reduceRight(function (accum, n, i) { | ||
return fn.call(_this21, accum, _this21.wrap(n), i); | ||
return fn.call(_this23, accum, _this23.wrap(n), i); | ||
}, initialValue); | ||
} | ||
return this.getNodesInternal().reduceRight(function (accum, n, i) { | ||
return fn.call(_this21, i === 1 ? _this21.wrap(accum) : accum, _this21.wrap(n), i); | ||
return fn.call(_this23, i === 1 ? _this23.wrap(accum) : accum, _this23.wrap(n), i); | ||
}); | ||
@@ -1456,6 +1469,6 @@ } | ||
function someWhere(predicate) { | ||
var _this22 = this; | ||
var _this24 = this; | ||
return this.getNodesInternal().some(function (n, i) { | ||
return predicate.call(_this22, _this22.wrap(n), i); | ||
return predicate.call(_this24, _this24.wrap(n), i); | ||
}); | ||
@@ -1496,6 +1509,6 @@ } | ||
function everyWhere(predicate) { | ||
var _this23 = this; | ||
var _this25 = this; | ||
return this.getNodesInternal().every(function (n, i) { | ||
return predicate.call(_this23, _this23.wrap(n), i); | ||
return predicate.call(_this25, _this25.wrap(n), i); | ||
}); | ||
@@ -1520,6 +1533,6 @@ } | ||
function flatMap(fn) { | ||
var _this24 = this; | ||
var _this26 = this; | ||
var nodes = this.getNodesInternal().map(function (n, i) { | ||
return fn.call(_this24, _this24.wrap(n), i); | ||
return fn.call(_this26, _this26.wrap(n), i); | ||
}); | ||
@@ -1545,6 +1558,6 @@ var flattened = (0, _arrayPrototype2['default'])(nodes, 1); | ||
function findWhere(predicate) { | ||
var _this25 = this; | ||
var _this27 = this; | ||
return findWhereUnwrapped(this, function (n) { | ||
return predicate(_this25.wrap(n)); | ||
return predicate(_this27.wrap(n)); | ||
}); | ||
@@ -1551,0 +1564,0 @@ } |
@@ -156,3 +156,3 @@ 'use strict'; | ||
function parentsOfNode(node, root) { | ||
return pathToNode(node, root).reverse(); | ||
return (pathToNode(node, root) || []).reverse(); | ||
} | ||
@@ -159,0 +159,0 @@ |
@@ -52,2 +52,4 @@ 'use strict'; | ||
var SET_STATE = (0, _Utils.sym)('__setState__'); | ||
var ROOT_NODES = (0, _Utils.sym)('__rootNodes__'); | ||
/** | ||
@@ -143,2 +145,8 @@ * Finds all nodes in the current wrapper nodes' render trees that match the provided predicate | ||
function getRootNodeInternal(wrapper) { | ||
if (wrapper[ROOT].length !== 1) { | ||
throw new Error('getRootNodeInternal(wrapper) can only be called when wrapper wraps one node'); | ||
} | ||
if (wrapper[ROOT] !== wrapper) { | ||
return wrapper[ROOT_NODES][0]; | ||
} | ||
return wrapper[ROOT][NODE]; | ||
@@ -228,2 +236,3 @@ } | ||
(0, _Utils.privateSet)(this, OPTIONS, root[OPTIONS]); | ||
(0, _Utils.privateSet)(this, ROOT_NODES, root[NODES]); | ||
} | ||
@@ -300,6 +309,7 @@ } | ||
function getElement() { | ||
if (this.length !== 1) { | ||
throw new Error('ShallowWrapper::getElement() can only be called when wrapping one node'); | ||
} | ||
return (0, _getAdapter2['default'])(this[OPTIONS]).nodeToElement(this.getNodeInternal()); | ||
var _this2 = this; | ||
return this.single('getElement', function (n) { | ||
return (0, _getAdapter2['default'])(_this2[OPTIONS]).nodeToElement(n); | ||
}); | ||
} | ||
@@ -435,3 +445,3 @@ | ||
function rerender(props, context) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -444,12 +454,12 @@ var adapter = (0, _getAdapter2['default'])(this[OPTIONS]); | ||
// this case, state will be undefined, but props/context will exist. | ||
var instance = _this2.instance() || {}; | ||
var instance = _this3.instance() || {}; | ||
var state = instance.state; | ||
var prevProps = instance.props || _this2[UNRENDERED].props; | ||
var prevContext = instance.context || _this2[OPTIONS].context; | ||
var prevProps = instance.props || _this3[UNRENDERED].props; | ||
var prevContext = instance.context || _this3[OPTIONS].context; | ||
var nextContext = context || prevContext; | ||
if (context) { | ||
_this2[OPTIONS] = (0, _object2['default'])({}, _this2[OPTIONS], { context: nextContext }); | ||
_this3[OPTIONS] = (0, _object2['default'])({}, _this3[OPTIONS], { context: nextContext }); | ||
} | ||
_this2[RENDERER].batchedUpdates(function () { | ||
_this3[RENDERER].batchedUpdates(function () { | ||
// When shouldComponentUpdate returns false we shouldn't call componentDidUpdate. | ||
@@ -459,3 +469,3 @@ // so we spy shouldComponentUpdate to get the result. | ||
var spy = void 0; | ||
if (!_this2[OPTIONS].disableLifecycleMethods && instance && typeof instance.shouldComponentUpdate === 'function') { | ||
if (!_this3[OPTIONS].disableLifecycleMethods && instance && typeof instance.shouldComponentUpdate === 'function') { | ||
spy = (0, _Utils.spyMethod)(instance, 'shouldComponentUpdate'); | ||
@@ -465,4 +475,4 @@ } else if (isPureComponent(instance)) { | ||
} | ||
if (props) _this2[UNRENDERED] = (0, _Utils.cloneElement)(adapter, _this2[UNRENDERED], props); | ||
_this2[RENDERER].render(_this2[UNRENDERED], nextContext); | ||
if (props) _this3[UNRENDERED] = (0, _Utils.cloneElement)(adapter, _this3[UNRENDERED], props); | ||
_this3[RENDERER].render(_this3[UNRENDERED], nextContext); | ||
if (spy) { | ||
@@ -472,3 +482,3 @@ shouldRender = spy.getLastReturnValue(); | ||
} | ||
if (shouldRender && !_this2[OPTIONS].disableLifecycleMethods && instance) { | ||
if (shouldRender && !_this3[OPTIONS].disableLifecycleMethods && instance) { | ||
var lifecycles = getAdapterLifecycles(adapter); | ||
@@ -495,3 +505,3 @@ | ||
} | ||
_this2.update(); | ||
_this3.update(); | ||
}); | ||
@@ -561,3 +571,3 @@ }); | ||
function setState(state) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -578,7 +588,7 @@ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
(0, _Utils.withSetStateAllowed)(function () { | ||
var adapter = (0, _getAdapter2['default'])(_this3[OPTIONS]); | ||
var adapter = (0, _getAdapter2['default'])(_this4[OPTIONS]); | ||
var lifecycles = getAdapterLifecycles(adapter); | ||
var instance = _this3.instance(); | ||
var instance = _this4.instance(); | ||
var prevProps = instance.props; | ||
@@ -598,3 +608,3 @@ var prevState = instance.state; | ||
var shouldRender = true; | ||
if (!_this3[OPTIONS].disableLifecycleMethods && lifecycles.componentDidUpdate && lifecycles.componentDidUpdate.onSetState && instance && typeof instance.shouldComponentUpdate === 'function') { | ||
if (!_this4[OPTIONS].disableLifecycleMethods && lifecycles.componentDidUpdate && lifecycles.componentDidUpdate.onSetState && instance && typeof instance.shouldComponentUpdate === 'function') { | ||
spy = (0, _Utils.spyMethod)(instance, 'shouldComponentUpdate'); | ||
@@ -615,3 +625,3 @@ } else if (isPureComponent(instance)) { | ||
} | ||
if (maybeHasUpdate && shouldRender && !_this3[OPTIONS].disableLifecycleMethods && lifecycles.componentDidUpdate && lifecycles.componentDidUpdate.onSetState && instance) { | ||
if (maybeHasUpdate && shouldRender && !_this4[OPTIONS].disableLifecycleMethods && lifecycles.componentDidUpdate && lifecycles.componentDidUpdate.onSetState && instance) { | ||
if (lifecycles.getSnapshotBeforeUpdate && typeof instance.getSnapshotBeforeUpdate === 'function') { | ||
@@ -630,3 +640,3 @@ var snapshot = instance.getSnapshotBeforeUpdate(prevProps, prevState); | ||
} | ||
_this3.update(); | ||
_this4.update(); | ||
// call the setState callback | ||
@@ -772,3 +782,3 @@ if (callback) { | ||
function containsAllMatchingElements(nodes) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -780,3 +790,3 @@ if (!Array.isArray(nodes)) { | ||
return nodes.every(function (node) { | ||
return _this4.containsMatchingElement(node); | ||
return _this5.containsMatchingElement(node); | ||
}); | ||
@@ -812,6 +822,6 @@ } | ||
function containsAnyMatchingElements(nodes) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
return Array.isArray(nodes) && nodes.some(function (node) { | ||
return _this5.containsMatchingElement(node); | ||
return _this6.containsMatchingElement(node); | ||
}); | ||
@@ -840,6 +850,6 @@ } | ||
function equals(node) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
return this.single('equals', function () { | ||
return (0, _Utils.nodeEqual)(_this6.getNodeInternal(), node); | ||
return (0, _Utils.nodeEqual)(_this7.getNodeInternal(), node); | ||
}); | ||
@@ -873,8 +883,8 @@ } | ||
function matchesElement(node) { | ||
var _this7 = this; | ||
var _this8 = this; | ||
return this.single('matchesElement', function () { | ||
var adapter = (0, _getAdapter2['default'])(_this7[OPTIONS]); | ||
var adapter = (0, _getAdapter2['default'])(_this8[OPTIONS]); | ||
var rstNode = adapter.elementToNode(node); | ||
return (0, _Utils.nodeMatches)(rstNode, _this7.getNodeInternal(), function (a, b) { | ||
return (0, _Utils.nodeMatches)(rstNode, _this8.getNodeInternal(), function (a, b) { | ||
return a <= b; | ||
@@ -956,6 +966,6 @@ }); | ||
function filterWhere(predicate) { | ||
var _this8 = this; | ||
var _this9 = this; | ||
return filterWhereUnwrapped(this, function (n) { | ||
return predicate(_this8.wrap(n)); | ||
return predicate(_this9.wrap(n)); | ||
}); | ||
@@ -1039,8 +1049,8 @@ } | ||
function html() { | ||
var _this9 = this; | ||
var _this10 = this; | ||
return this.single('html', function (n) { | ||
if (_this9.type() === null) return null; | ||
var adapter = (0, _getAdapter2['default'])(_this9[OPTIONS]); | ||
var renderer = adapter.createRenderer((0, _object2['default'])({}, _this9[OPTIONS], { mode: 'string' })); | ||
if (_this10.type() === null) return null; | ||
var adapter = (0, _getAdapter2['default'])(_this10[OPTIONS]); | ||
var renderer = adapter.createRenderer((0, _object2['default'])({}, _this10[OPTIONS], { mode: 'string' })); | ||
return renderer.render(adapter.nodeToElement(n)); | ||
@@ -1084,3 +1094,3 @@ }); | ||
function simulate(event) { | ||
var _this10 = this; | ||
var _this11 = this; | ||
@@ -1094,5 +1104,5 @@ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
(_RENDERER = _this10[RENDERER]).simulateEvent.apply(_RENDERER, [n, event].concat(args)); | ||
_this10[ROOT].update(); | ||
return _this10; | ||
(_RENDERER = _this11[RENDERER]).simulateEvent.apply(_RENDERER, [n, event].concat(args)); | ||
_this11[ROOT].update(); | ||
return _this11; | ||
}); | ||
@@ -1115,3 +1125,3 @@ } | ||
function simulateError(error) { | ||
var _this11 = this; | ||
var _this12 = this; | ||
@@ -1125,3 +1135,3 @@ // in shallow, the "root" is the "rendered" thing. | ||
var renderer = _this11[RENDERER]; | ||
var renderer = _this12[RENDERER]; | ||
if (typeof renderer.simulateError !== 'function') { | ||
@@ -1131,7 +1141,7 @@ throw new TypeError('your adapter does not support `simulateError`. Try upgrading it!'); | ||
var rootNode = getRootNodeInternal(_this11); | ||
var nodeHierarchy = [thisNode].concat(nodeParents(_this11, thisNode)); | ||
var rootNode = getRootNodeInternal(_this12); | ||
var nodeHierarchy = [thisNode].concat(nodeParents(_this12, thisNode)); | ||
renderer.simulateError(nodeHierarchy, rootNode, error); | ||
return _this11; | ||
return _this12; | ||
}); | ||
@@ -1175,3 +1185,3 @@ } | ||
function state(name) { | ||
var _this12 = this; | ||
var _this13 = this; | ||
@@ -1185,5 +1195,8 @@ if (this[ROOT] !== this) { | ||
var _state = this.single('state', function () { | ||
return _this12.instance().state; | ||
return _this13.instance().state; | ||
}); | ||
if (typeof name !== 'undefined') { | ||
if (_state == null) { | ||
throw new TypeError('ShallowWrapper::state("' + String(name) + '") requires that `state` not be `null` or `undefined`'); | ||
} | ||
return _state[name]; | ||
@@ -1211,3 +1224,3 @@ } | ||
function context(name) { | ||
var _this13 = this; | ||
var _this14 = this; | ||
@@ -1224,3 +1237,3 @@ if (this[ROOT] !== this) { | ||
var _context = this.single('context', function () { | ||
return _this13.instance().context; | ||
return _this14.instance().context; | ||
}); | ||
@@ -1267,6 +1280,6 @@ if (name) { | ||
function childAt(index) { | ||
var _this14 = this; | ||
var _this15 = this; | ||
return this.single('childAt', function () { | ||
return _this14.children().at(index); | ||
return _this15.children().at(index); | ||
}); | ||
@@ -1292,8 +1305,8 @@ } | ||
function parents(selector) { | ||
var _this15 = this; | ||
var _this16 = this; | ||
var allParents = this.wrap(this.single('parents', function (n) { | ||
return nodeParents(_this15, n); | ||
})); | ||
return selector ? allParents.filter(selector) : allParents; | ||
return this.single('parents', function (n) { | ||
var allParents = _this16.wrap(nodeParents(_this16, n)); | ||
return selector ? allParents.filter(selector) : allParents; | ||
}); | ||
} | ||
@@ -1357,6 +1370,6 @@ | ||
function shallow(options) { | ||
var _this16 = this; | ||
var _this17 = this; | ||
return this.single('shallow', function (n) { | ||
return _this16.wrap((0, _getAdapter2['default'])(_this16[OPTIONS]).nodeToElement(n), null, options); | ||
return _this17.wrap((0, _getAdapter2['default'])(_this17[OPTIONS]).nodeToElement(n), null, options); | ||
}); | ||
@@ -1481,6 +1494,6 @@ } | ||
function forEach(fn) { | ||
var _this17 = this; | ||
var _this18 = this; | ||
this.getNodesInternal().forEach(function (n, i) { | ||
return fn.call(_this17, _this17.wrap(n), i); | ||
return fn.call(_this18, _this18.wrap(n), i); | ||
}); | ||
@@ -1505,6 +1518,6 @@ return this; | ||
function map(fn) { | ||
var _this18 = this; | ||
var _this19 = this; | ||
return this.getNodesInternal().map(function (n, i) { | ||
return fn.call(_this18, _this18.wrap(n), i); | ||
return fn.call(_this19, _this19.wrap(n), i); | ||
}); | ||
@@ -1529,3 +1542,3 @@ } | ||
function reduce(fn) { | ||
var _this19 = this; | ||
var _this20 = this; | ||
@@ -1536,7 +1549,7 @@ var initialValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return this.getNodesInternal().reduce(function (accum, n, i) { | ||
return fn.call(_this19, accum, _this19.wrap(n), i); | ||
return fn.call(_this20, accum, _this20.wrap(n), i); | ||
}, initialValue); | ||
} | ||
return this.getNodesInternal().reduce(function (accum, n, i) { | ||
return fn.call(_this19, i === 1 ? _this19.wrap(accum) : accum, _this19.wrap(n), i); | ||
return fn.call(_this20, i === 1 ? _this20.wrap(accum) : accum, _this20.wrap(n), i); | ||
}); | ||
@@ -1561,3 +1574,3 @@ } | ||
function reduceRight(fn) { | ||
var _this20 = this; | ||
var _this21 = this; | ||
@@ -1568,7 +1581,7 @@ var initialValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return this.getNodesInternal().reduceRight(function (accum, n, i) { | ||
return fn.call(_this20, accum, _this20.wrap(n), i); | ||
return fn.call(_this21, accum, _this21.wrap(n), i); | ||
}, initialValue); | ||
} | ||
return this.getNodesInternal().reduceRight(function (accum, n, i) { | ||
return fn.call(_this20, i === 1 ? _this20.wrap(accum) : accum, _this20.wrap(n), i); | ||
return fn.call(_this21, i === 1 ? _this21.wrap(accum) : accum, _this21.wrap(n), i); | ||
}); | ||
@@ -1631,6 +1644,6 @@ } | ||
function someWhere(predicate) { | ||
var _this21 = this; | ||
var _this22 = this; | ||
return this.getNodesInternal().some(function (n, i) { | ||
return predicate.call(_this21, _this21.wrap(n), i); | ||
return predicate.call(_this22, _this22.wrap(n), i); | ||
}); | ||
@@ -1671,6 +1684,6 @@ } | ||
function everyWhere(predicate) { | ||
var _this22 = this; | ||
var _this23 = this; | ||
return this.getNodesInternal().every(function (n, i) { | ||
return predicate.call(_this22, _this22.wrap(n), i); | ||
return predicate.call(_this23, _this23.wrap(n), i); | ||
}); | ||
@@ -1695,6 +1708,6 @@ } | ||
function flatMap(fn) { | ||
var _this23 = this; | ||
var _this24 = this; | ||
var nodes = this.getNodesInternal().map(function (n, i) { | ||
return fn.call(_this23, _this23.wrap(n), i); | ||
return fn.call(_this24, _this24.wrap(n), i); | ||
}); | ||
@@ -1721,6 +1734,6 @@ var flattened = (0, _arrayPrototype2['default'])(nodes, 1); | ||
function findWhere(predicate) { | ||
var _this24 = this; | ||
var _this25 = this; | ||
return findWhereUnwrapped(this, function (n) { | ||
return predicate(_this24.wrap(n)); | ||
return predicate(_this25.wrap(n)); | ||
}); | ||
@@ -1946,3 +1959,3 @@ } | ||
function dive() { | ||
var _this25 = this; | ||
var _this26 = this; | ||
@@ -1957,7 +1970,7 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
} | ||
var el = (0, _getAdapter2['default'])(_this25[OPTIONS]).nodeToElement(n); | ||
var el = (0, _getAdapter2['default'])(_this26[OPTIONS]).nodeToElement(n); | ||
if (!(0, _Utils.isCustomComponentElement)(el, adapter)) { | ||
throw new TypeError('ShallowWrapper::' + name + '() can only be called on components'); | ||
} | ||
return _this25.wrap(el, null, (0, _object2['default'])({}, _this25[OPTIONS], options)); | ||
return _this26.wrap(el, null, (0, _object2['default'])({}, _this26[OPTIONS], options)); | ||
}); | ||
@@ -1964,0 +1977,0 @@ } |
@@ -10,5 +10,4 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /* eslint no-use-before-define: 0 */ | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.getAdapter = getAdapter; | ||
@@ -77,2 +76,5 @@ exports.makeOptions = makeOptions; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /* eslint no-use-before-define: 0 */ | ||
var ITERATOR_SYMBOL = exports.ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
@@ -87,11 +89,21 @@ | ||
function validateMountOptions(attachTo, hydrateIn) { | ||
if (attachTo && hydrateIn && attachTo !== hydrateIn) { | ||
throw new TypeError('If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)'); | ||
} | ||
} | ||
function makeOptions(options) { | ||
var _get = (0, _configuration.get)(), | ||
configAttachTo = _get.attachTo, | ||
configHydrateIn = _get.hydrateIn, | ||
config = _objectWithoutProperties(_get, ['attachTo', 'hydrateIn']); | ||
validateMountOptions(configAttachTo, configHydrateIn); | ||
var attachTo = options.attachTo, | ||
hydrateIn = options.hydrateIn; | ||
validateMountOptions(attachTo, hydrateIn); | ||
if (attachTo && hydrateIn && attachTo !== hydrateIn) { | ||
throw new TypeError('If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)'); | ||
} | ||
// neither present: both undefined | ||
@@ -101,11 +113,13 @@ // only attachTo present: attachTo set, hydrateIn undefined | ||
// both present (and ===, per above): both set to hydrateIn | ||
var mountTargets = { | ||
attachTo: hydrateIn || attachTo || undefined, | ||
hydrateIn: hydrateIn || undefined | ||
}; | ||
var finalAttachTo = hydrateIn || configHydrateIn || configAttachTo || attachTo || undefined; | ||
var finalHydrateIn = hydrateIn || configHydrateIn || undefined; | ||
var mountTargets = (0, _object2['default'])({}, finalAttachTo && { attachTo: finalAttachTo }, finalHydrateIn && { hydrateIn: finalHydrateIn }); | ||
return (0, _object2['default'])({}, (0, _configuration.get)(), options, mountTargets); | ||
return (0, _object2['default'])({}, config, options, mountTargets); | ||
} | ||
function isCustomComponentElement(inst, adapter) { | ||
if (adapter.isCustomComponentElement) { | ||
return !!adapter.isCustomComponentElement(inst); | ||
} | ||
return !!inst && adapter.isValidElement(inst) && typeof inst.type === 'function'; | ||
@@ -112,0 +126,0 @@ } |
{ | ||
"name": "enzyme", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"description": "JavaScript Testing utilities for React", | ||
@@ -60,4 +60,4 @@ "homepage": "http://airbnb.io/enzyme/", | ||
"babel-plugin-transform-replace-object-assign": "^1.0.0", | ||
"babel-preset-airbnb": "^2.5.3", | ||
"eslint": "^5.4.0", | ||
"babel-preset-airbnb": "^2.6.0", | ||
"eslint": "^5.6.1", | ||
"eslint-config-airbnb": "^17.1.0", | ||
@@ -64,0 +64,0 @@ "eslint-plugin-import": "^2.14.0", |
import validateAdapter from './validateAdapter'; | ||
const configuration = {}; | ||
let configuration = {}; | ||
@@ -15,1 +15,6 @@ export function get() { | ||
} | ||
export function reset(replacementConfig = {}) { | ||
configuration = {}; | ||
merge(replacementConfig); | ||
} |
@@ -34,2 +34,3 @@ import cheerio from 'cheerio'; | ||
const OPTIONS = sym('__options__'); | ||
const ROOT_NODES = sym('__rootNodes__'); | ||
@@ -61,4 +62,14 @@ /** | ||
function getRootNodeInternal(wrapper) { | ||
if (wrapper[ROOT].length !== 1) { | ||
throw new Error('getRootNodeInternal(wrapper) can only be called when wrapper wraps one node'); | ||
} | ||
if (wrapper[ROOT] !== wrapper) { | ||
return wrapper[ROOT_NODES][0]; | ||
} | ||
return wrapper[ROOT][NODE]; | ||
} | ||
function nodeParents(wrapper, node) { | ||
return parentsOfNode(node, wrapper[ROOT].getNodeInternal()); | ||
return parentsOfNode(node, getRootNodeInternal(wrapper)); | ||
} | ||
@@ -107,2 +118,3 @@ | ||
privateSetNodes(this, nodes); | ||
privateSet(this, ROOT_NODES, root[NODES]); | ||
} | ||
@@ -148,6 +160,3 @@ privateSet(this, OPTIONS, root ? root[OPTIONS] : options); | ||
getElement() { | ||
if (this.length !== 1) { | ||
throw new Error('ReactWrapper::getElement() can only be called when wrapping one node'); | ||
} | ||
return getAdapter(this[OPTIONS]).nodeToElement(this[NODE]); | ||
return this.single('getElement', () => getAdapter(this[OPTIONS]).nodeToElement(this[NODE])); | ||
} | ||
@@ -214,6 +223,3 @@ | ||
instance() { | ||
if (this.length !== 1) { | ||
throw new Error('ReactWrapper::instance() can only be called on single nodes'); | ||
} | ||
return this[NODE].instance; | ||
return this.single('instance', () => this[NODE].instance); | ||
} | ||
@@ -225,3 +231,3 @@ | ||
* | ||
* NOTE: can only be called on a wrapper instance that is also the root instance. | ||
* NOTE: no matter what instance this is called on, it will always update the root. | ||
* | ||
@@ -231,4 +237,5 @@ * @returns {ReactWrapper} | ||
update() { | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::update() can only be called on the root'); | ||
const root = this[ROOT]; | ||
if (this !== root) { | ||
return root.update(); | ||
} | ||
@@ -317,5 +324,2 @@ privateSetNodes(this, this[RENDERER].getNode()); | ||
setState(state, callback = undefined) { | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::setState() can only be called on the root'); | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
@@ -650,6 +654,7 @@ throw new Error('ReactWrapper::setState() can only be called on class components'); | ||
const rootNode = this[ROOT].getNodeInternal(); | ||
const rootNode = getRootNodeInternal(this); | ||
const nodeHierarchy = [thisNode].concat(nodeParents(this, thisNode)); | ||
renderer.simulateError(nodeHierarchy, rootNode, error); | ||
this[ROOT].update(); | ||
return this; | ||
@@ -680,5 +685,2 @@ }); | ||
state(name) { | ||
if (this[ROOT] !== this) { | ||
throw new Error('ReactWrapper::state() can only be called on the root'); | ||
} | ||
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') { | ||
@@ -689,2 +691,5 @@ throw new Error('ReactWrapper::state() can only be called on class components'); | ||
if (typeof name !== 'undefined') { | ||
if (_state == null) { | ||
throw new TypeError(`ReactWrapper::state("${name}") requires that \`state\` not be \`null\` or \`undefined\``); | ||
} | ||
return _state[name]; | ||
@@ -750,4 +755,6 @@ } | ||
parents(selector) { | ||
const allParents = this.wrap(this.single('parents', n => nodeParents(this, n))); | ||
return selector ? allParents.filter(selector) : allParents; | ||
return this.single('parents', (n) => { | ||
const allParents = this.wrap(nodeParents(this, n)); | ||
return selector ? allParents.filter(selector) : allParents; | ||
}); | ||
} | ||
@@ -754,0 +761,0 @@ |
@@ -109,3 +109,3 @@ import flat from 'array.prototype.flat'; | ||
export function parentsOfNode(node, root) { | ||
return pathToNode(node, root).reverse(); | ||
return (pathToNode(node, root) || []).reverse(); | ||
} | ||
@@ -112,0 +112,0 @@ |
@@ -40,2 +40,4 @@ import flat from 'array.prototype.flat'; | ||
const SET_STATE = sym('__setState__'); | ||
const ROOT_NODES = sym('__rootNodes__'); | ||
/** | ||
@@ -148,2 +150,8 @@ * Finds all nodes in the current wrapper nodes' render trees that match the provided predicate | ||
function getRootNodeInternal(wrapper) { | ||
if (wrapper[ROOT].length !== 1) { | ||
throw new Error('getRootNodeInternal(wrapper) can only be called when wrapper wraps one node'); | ||
} | ||
if (wrapper[ROOT] !== wrapper) { | ||
return wrapper[ROOT_NODES][0]; | ||
} | ||
return wrapper[ROOT][NODE]; | ||
@@ -224,2 +232,3 @@ } | ||
privateSet(this, OPTIONS, root[OPTIONS]); | ||
privateSet(this, ROOT_NODES, root[NODES]); | ||
} | ||
@@ -270,6 +279,3 @@ } | ||
getElement() { | ||
if (this.length !== 1) { | ||
throw new Error('ShallowWrapper::getElement() can only be called when wrapping one node'); | ||
} | ||
return getAdapter(this[OPTIONS]).nodeToElement(this.getNodeInternal()); | ||
return this.single('getElement', n => getAdapter(this[OPTIONS]).nodeToElement(n)); | ||
} | ||
@@ -917,2 +923,5 @@ | ||
if (typeof name !== 'undefined') { | ||
if (_state == null) { | ||
throw new TypeError(`ShallowWrapper::state("${name}") requires that \`state\` not be \`null\` or \`undefined\``); | ||
} | ||
return _state[name]; | ||
@@ -980,4 +989,6 @@ } | ||
parents(selector) { | ||
const allParents = this.wrap(this.single('parents', n => nodeParents(this, n))); | ||
return selector ? allParents.filter(selector) : allParents; | ||
return this.single('parents', (n) => { | ||
const allParents = this.wrap(nodeParents(this, n)); | ||
return selector ? allParents.filter(selector) : allParents; | ||
}); | ||
} | ||
@@ -984,0 +995,0 @@ |
@@ -21,9 +21,15 @@ /* eslint no-use-before-define: 0 */ | ||
export function makeOptions(options) { | ||
const { attachTo, hydrateIn } = options; | ||
function validateMountOptions(attachTo, hydrateIn) { | ||
if (attachTo && hydrateIn && attachTo !== hydrateIn) { | ||
throw new TypeError('If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)'); | ||
} | ||
} | ||
export function makeOptions(options) { | ||
const { attachTo: configAttachTo, hydrateIn: configHydrateIn, ...config } = get(); | ||
validateMountOptions(configAttachTo, configHydrateIn); | ||
const { attachTo, hydrateIn } = options; | ||
validateMountOptions(attachTo, hydrateIn); | ||
// neither present: both undefined | ||
@@ -33,9 +39,11 @@ // only attachTo present: attachTo set, hydrateIn undefined | ||
// both present (and ===, per above): both set to hydrateIn | ||
const finalAttachTo = hydrateIn || configHydrateIn || configAttachTo || attachTo || undefined; | ||
const finalHydrateIn = hydrateIn || configHydrateIn || undefined; | ||
const mountTargets = { | ||
attachTo: hydrateIn || attachTo || undefined, | ||
hydrateIn: hydrateIn || undefined, | ||
...(finalAttachTo && { attachTo: finalAttachTo }), | ||
...(finalHydrateIn && { hydrateIn: finalHydrateIn }), | ||
}; | ||
return { | ||
...get(), | ||
...config, | ||
...options, | ||
@@ -47,2 +55,5 @@ ...mountTargets, | ||
export function isCustomComponentElement(inst, adapter) { | ||
if (adapter.isCustomComponentElement) { | ||
return !!adapter.isCustomComponentElement(inst); | ||
} | ||
return !!inst && adapter.isValidElement(inst) && typeof inst.type === 'function'; | ||
@@ -49,0 +60,0 @@ } |
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
293851
7990