Skip to content

Commit

Permalink
[enzyme, enzyme-adapter-react-16] [new] add matchesElementType
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 1, 2019
1 parent 9cc5f44 commit 65881b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/enzyme-adapter-react-16/src/ReactSixteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,18 @@ class ReactSixteenAdapter extends EnzymeAdapter {
return React.createElement(isMemo(type) ? type.type : type, propsWithKeysAndRef(node));
}

matchesElementType(node, matchingType) {
if (!node) {
return node;
}
const { type } = node;

const nodeType = isMemo(type) ? type.type : type;
const matchingTypeType = isMemo(matchingType) ? matchingType.type : matchingType;
// console.log('**', isMemo(type), type === matchingType, type.type === matchingType, type === matchingType.type, type.type === matchingType.type);
return nodeType === matchingTypeType;
}

elementToNode(element) {
return elementToTree(element);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/enzyme/src/EnzymeAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class EnzymeAdapter {
throw unimplementedError('nodeToElement', 'EnzymeAdapter');
}

matchesElementType(node, matchingType) {
if (!node) {
return node;
}
const { type } = node;
return type === matchingType;
}

// eslint-disable-next-line class-methods-use-this, no-unused-vars
isValidElement(element) {
throw unimplementedError('isValidElement', 'EnzymeAdapter');
Expand Down

0 comments on commit 65881b2

Please sign in to comment.