+ );
+ }
+ }
+ const spy = sinon.spy(Foo.prototype, 'componentDidMount');
+
+ const wrapper = shallow();
+ expect(spy).to.have.property('callCount', 1);
+ wrapper.find('button').prop('onClick')();
+ expect(spy).to.have.property('callCount', 1);
+ });
+ });
});
diff --git a/packages/enzyme/src/ReactWrapper.js b/packages/enzyme/src/ReactWrapper.js
index 015f1b6b0..73a799e05 100644
--- a/packages/enzyme/src/ReactWrapper.js
+++ b/packages/enzyme/src/ReactWrapper.js
@@ -347,30 +347,6 @@ class ReactWrapper {
return this;
}
- /**
- * Whether or not a given react element matches the current render tree.
- * It will determine if the wrapper root node "looks like" the expected
- * element by checking if all props of the expected element are present
- * on the wrapper root node and equals to each other.
- *
- * Example:
- * ```
- * // MyComponent outputs
)).to.equal(true);
- * ```
- *
- * @param {ReactElement} node
- * @returns {Boolean}
- */
- matchesElement(node) {
- return this.single('matchesElement', () => {
- const adapter = getAdapter(this[OPTIONS]);
- const rstNode = adapter.elementToNode(node);
- return nodeMatches(rstNode, this.getNodeInternal(), (a, b) => a <= b);
- });
- }
-
/**
* Whether or not a given react element exists in the mount render tree.
*
@@ -468,7 +444,7 @@ class ReactWrapper {
}
/**
- * Whether or not a given react element exists in the current render tree.
+ * Whether or not a given react element exists in the render tree.
*
* Example:
* ```
@@ -483,6 +459,31 @@ class ReactWrapper {
return this.single('equals', () => nodeEqual(this.getNodeInternal(), node));
}
+ /**
+ * Whether or not a given react element matches the render tree.
+ * Match is based on the expected element and not on wrapper root node.
+ * It will determine if the wrapper root node "looks like" the expected
+ * element by checking if all props of the expected element are present
+ * on the wrapper root node and equals to each other.
+ *
+ * Example:
+ * ```
+ * // MyComponent outputs
)).to.equal(true);
+ * ```
+ *
+ * @param {ReactElement} node
+ * @returns {Boolean}
+ */
+ matchesElement(node) {
+ return this.single('matchesElement', () => {
+ const adapter = getAdapter(this[OPTIONS]);
+ const rstNode = adapter.elementToNode(node);
+ return nodeMatches(rstNode, this.getNodeInternal(), (a, b) => a <= b);
+ });
+ }
+
/**
* Finds every node in the render tree of the current wrapper that matches the provided selector.
*
@@ -1089,7 +1090,6 @@ class ReactWrapper {
}
}
-
if (ITERATOR_SYMBOL) {
Object.defineProperty(ReactWrapper.prototype, ITERATOR_SYMBOL, {
configurable: true,
diff --git a/packages/enzyme/src/ShallowWrapper.js b/packages/enzyme/src/ShallowWrapper.js
index ecc29f220..469de0b64 100644
--- a/packages/enzyme/src/ShallowWrapper.js
+++ b/packages/enzyme/src/ShallowWrapper.js
@@ -227,6 +227,11 @@ class ShallowWrapper {
return this[ROOT];
}
+ /**
+ * Returns the wrapped component.
+ *
+ * @return {ReactComponent}
+ */
getNodeInternal() {
if (this.length !== 1) {
throw new Error('ShallowWrapper::getNode() can only be called when wrapping one node');
@@ -237,6 +242,18 @@ class ShallowWrapper {
return this[NODE];
}
+ /**
+ * Returns the the wrapped components.
+ *
+ * @return {Array}
+ */
+ getNodesInternal() {
+ if (this[ROOT] === this && this.length === 1) {
+ this.update();
+ }
+ return this[NODES];
+ }
+
/**
* Returns the wrapped ReactElement.
*
@@ -263,13 +280,6 @@ class ShallowWrapper {
throw new Error('ShallowWrapper::getNode() is no longer supported. Use ShallowWrapper::getElement() instead');
}
- getNodesInternal() {
- if (this[ROOT] === this && this.length === 1) {
- this.update();
- }
- return this[NODES];
- }
-
// eslint-disable-next-line class-methods-use-this
getNodes() {
throw new Error('ShallowWrapper::getNodes() is no longer supported. Use ShallowWrapper::getElements() instead');
@@ -314,6 +324,16 @@ class ShallowWrapper {
return this;
}
+ /**
+ * A method that unmounts the component. This can be used to simulate a component going through
+ * and unmount/mount lifecycle.
+ * @returns {ShallowWrapper}
+ */
+ unmount() {
+ this[RENDERER].unmount();
+ return this;
+ }
+
/**
* A method is for re-render with new props and context.
* This calls componentDidUpdate method if disableLifecycleMethods is not enabled.
@@ -666,7 +686,7 @@ class ShallowWrapper {
}
/**
- * Whether or not a given react element exists in the shallow render tree.
+ * Whether or not a given react element exists in the render tree.
*
* Example:
* ```
@@ -682,7 +702,7 @@ class ShallowWrapper {
}
/**
- * Whether or not a given react element matches the shallow render tree.
+ * Whether or not a given react element matches the render tree.
* Match is based on the expected element and not on wrapper root node.
* It will determine if the wrapper root node "looks like" the expected
* element by checking if all props of the expected element are present
@@ -814,16 +834,6 @@ class ShallowWrapper {
return this.type() === null ? cheerio() : cheerio.load('')(this.html());
}
- /**
- * A method that unmounts the component. This can be used to simulate a component going through
- * and unmount/mount lifecycle.
- * @returns {ShallowWrapper}
- */
- unmount() {
- this[RENDERER].unmount();
- return this;
- }
-
/**
* Used to simulate events. Pass an eventname and (optionally) event arguments. This method of
* testing events should be met with some skepticism.