Skip to content

Commit 73334a7

Browse files
authored
Merge pull request #1423 from eddyerburgh/master
[Fix] Convert nodes to RST nodes before comparing
2 parents cf52af4 + 2f299d1 commit 73334a7

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

packages/enzyme/src/ReactWrapper.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ class ReactWrapper {
358358
* @returns {Boolean}
359359
*/
360360
matchesElement(node) {
361-
return this.single('matchesElement', () => nodeMatches(node, this.getNodeInternal(), (a, b) => a <= b));
361+
return this.single('matchesElement', () => {
362+
const rstNode = getAdapter().elementToNode(node);
363+
return nodeMatches(rstNode, this.getNodeInternal(), (a, b) => a <= b);
364+
});
362365
}
363366

364367
/**
@@ -374,9 +377,16 @@ class ReactWrapper {
374377
* @returns {Boolean}
375378
*/
376379
contains(nodeOrNodes) {
380+
const adapter = getAdapter(this[OPTIONS]);
381+
377382
const predicate = Array.isArray(nodeOrNodes)
378-
? other => containsChildrenSubArray(nodeEqual, other, nodeOrNodes)
379-
: other => nodeEqual(nodeOrNodes, other);
383+
? other => containsChildrenSubArray(
384+
nodeEqual,
385+
other,
386+
nodeOrNodes.map(node => adapter.elementToNode(node)),
387+
)
388+
: other => nodeEqual(adapter.elementToNode(nodeOrNodes), other);
389+
380390
return findWhereUnwrapped(this, predicate).length > 0;
381391
}
382392

@@ -397,7 +407,8 @@ class ReactWrapper {
397407
* @returns {Boolean}
398408
*/
399409
containsMatchingElement(node) {
400-
const predicate = other => nodeMatches(node, other, (a, b) => a <= b);
410+
const rstNode = getAdapter(this[OPTIONS]).elementToNode(node);
411+
const predicate = other => nodeMatches(rstNode, other, (a, b) => a <= b);
401412
return findWhereUnwrapped(this, predicate).length > 0;
402413
}
403414

packages/enzyme/src/ShallowWrapper.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ class ShallowWrapper {
451451
? other => containsChildrenSubArray(
452452
nodeEqual,
453453
other,
454-
nodeOrNodes.map(adapter.elementToNode),
454+
nodeOrNodes.map(node => adapter.elementToNode(node)),
455455
)
456456
: other => nodeEqual(adapter.elementToNode(nodeOrNodes), other);
457457

@@ -476,7 +476,8 @@ class ShallowWrapper {
476476
* @returns {Boolean}
477477
*/
478478
containsMatchingElement(node) {
479-
const predicate = other => nodeMatches(node, other, (a, b) => a <= b);
479+
const rstNode = getAdapter().elementToNode(node);
480+
const predicate = other => nodeMatches(rstNode, other, (a, b) => a <= b);
480481
return findWhereUnwrapped(this, predicate).length > 0;
481482
}
482483

@@ -564,7 +565,10 @@ class ShallowWrapper {
564565
* @returns {Boolean}
565566
*/
566567
matchesElement(node) {
567-
return this.single('matchesElement', () => nodeMatches(node, this.getNodeInternal(), (a, b) => a <= b));
568+
return this.single('matchesElement', () => {
569+
const rstNode = getAdapter().elementToNode(node);
570+
return nodeMatches(rstNode, this.getNodeInternal(), (a, b) => a <= b);
571+
});
568572
}
569573

570574
/**

0 commit comments

Comments
 (0)