Skip to content

Commit

Permalink
Add additional type checks to adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense authored and ljharb committed Jul 2, 2018
1 parent 0914749 commit 9b354d1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/enzyme/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ export function typeOfNode(node) {

export function nodeHasType(node, type) {
if (!type || !node) return false;

const adapter = getAdapter();
if (adapter.displayNameOfNode) {
const displayName = adapter.displayNameOfNode(node);
if (displayName === type) return true;
}

if (!node.type) return false;
if (typeof node.type === 'string') return node.type === type;
return (typeof node.type === 'function' ?
functionName(node.type) === type : node.type.name === type) || node.type.displayName === type;
return (
typeof node.type === 'function' ? functionName(node.type) === type : node.type.name === type
) || node.type.displayName === type;
}

function internalChildrenCompare(a, b, lenComp, isLoose) {
Expand Down Expand Up @@ -215,6 +223,7 @@ export function AND(fns) {
return x => fnsReversed.every(fn => fn(x));
}

// TODO: semver-major: remove
export function displayNameOfNode(node) {
if (!node) return null;

Expand Down

0 comments on commit 9b354d1

Please sign in to comment.