Skip to content

Commit

Permalink
Merge pull request #1423 from eddyerburgh/master
Browse files Browse the repository at this point in the history
[Fix] Convert nodes to RST nodes before comparing
  • Loading branch information
ljharb authored Jan 19, 2018
2 parents cf52af4 + 2f299d1 commit 73334a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 15 additions & 4 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ class ReactWrapper {
* @returns {Boolean}
*/
matchesElement(node) {
return this.single('matchesElement', () => nodeMatches(node, this.getNodeInternal(), (a, b) => a <= b));
return this.single('matchesElement', () => {
const rstNode = getAdapter().elementToNode(node);
return nodeMatches(rstNode, this.getNodeInternal(), (a, b) => a <= b);
});
}

/**
Expand All @@ -374,9 +377,16 @@ class ReactWrapper {
* @returns {Boolean}
*/
contains(nodeOrNodes) {
const adapter = getAdapter(this[OPTIONS]);

const predicate = Array.isArray(nodeOrNodes)
? other => containsChildrenSubArray(nodeEqual, other, nodeOrNodes)
: other => nodeEqual(nodeOrNodes, other);
? other => containsChildrenSubArray(
nodeEqual,
other,
nodeOrNodes.map(node => adapter.elementToNode(node)),
)
: other => nodeEqual(adapter.elementToNode(nodeOrNodes), other);

return findWhereUnwrapped(this, predicate).length > 0;
}

Expand All @@ -397,7 +407,8 @@ class ReactWrapper {
* @returns {Boolean}
*/
containsMatchingElement(node) {
const predicate = other => nodeMatches(node, other, (a, b) => a <= b);
const rstNode = getAdapter(this[OPTIONS]).elementToNode(node);
const predicate = other => nodeMatches(rstNode, other, (a, b) => a <= b);
return findWhereUnwrapped(this, predicate).length > 0;
}

Expand Down
10 changes: 7 additions & 3 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class ShallowWrapper {
? other => containsChildrenSubArray(
nodeEqual,
other,
nodeOrNodes.map(adapter.elementToNode),
nodeOrNodes.map(node => adapter.elementToNode(node)),
)
: other => nodeEqual(adapter.elementToNode(nodeOrNodes), other);

Expand All @@ -476,7 +476,8 @@ class ShallowWrapper {
* @returns {Boolean}
*/
containsMatchingElement(node) {
const predicate = other => nodeMatches(node, other, (a, b) => a <= b);
const rstNode = getAdapter().elementToNode(node);
const predicate = other => nodeMatches(rstNode, other, (a, b) => a <= b);
return findWhereUnwrapped(this, predicate).length > 0;
}

Expand Down Expand Up @@ -564,7 +565,10 @@ class ShallowWrapper {
* @returns {Boolean}
*/
matchesElement(node) {
return this.single('matchesElement', () => nodeMatches(node, this.getNodeInternal(), (a, b) => a <= b));
return this.single('matchesElement', () => {
const rstNode = getAdapter().elementToNode(node);
return nodeMatches(rstNode, this.getNodeInternal(), (a, b) => a <= b);
});
}

/**
Expand Down

0 comments on commit 73334a7

Please sign in to comment.