From 9b354d18858798ef44c59405441e0b49610e9443 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Mon, 2 Jul 2018 10:22:41 -0400 Subject: [PATCH] Add additional type checks to adapters --- packages/enzyme/src/Utils.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/enzyme/src/Utils.js b/packages/enzyme/src/Utils.js index 644bf0b1a..4f122e51b 100644 --- a/packages/enzyme/src/Utils.js +++ b/packages/enzyme/src/Utils.js @@ -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) { @@ -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;