Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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