diff --git a/src/findNode.ts b/src/findNode.ts index 4f62f58..94826b2 100644 --- a/src/findNode.ts +++ b/src/findNode.ts @@ -1,5 +1,5 @@ import { FiberNode } from "./mocked-types"; -import { isNotHtmlLike } from "./utils"; +import { isNodeNotHtmlLike } from "./utils"; function findNodeByComponentName( node: FiberNode | null, @@ -9,8 +9,7 @@ function findNodeByComponentName( return null; } - if (isNotHtmlLike(node) && node.type.name === expectedName) { - // console.debug("Found node " + node); + if (isNodeNotHtmlLike(node) && node.type.name === expectedName) { return node; } @@ -38,8 +37,7 @@ function findNodeByComponent( return null; } - if (isNotHtmlLike(node) && node.type === expectedClassOrFunction) { - // console.debug("Found node " + node); + if (isNodeNotHtmlLike(node) && node.type === expectedClassOrFunction) { return node; } @@ -67,8 +65,7 @@ function findNodeByComponentInstance( return null; } - if (isNotHtmlLike(node) && node.stateNode === expectedClassInstance) { - // console.debug("Found node " + node); + if (isNodeNotHtmlLike(node) && node.stateNode === expectedClassInstance) { return node; } diff --git a/src/utils.ts b/src/utils.ts index 58a1569..d03253e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,11 +1,20 @@ -import { FiberNode, FiberNodeisHTMLLike } from './mocked-types'; +import * as React from 'react'; +import { FiberNode, FiberNodeisHTMLLike, FiberNodeForFunctionComponent, FiberNodeForComponentClass } from './mocked-types'; -function isHtmlLike(node: FiberNode): node is FiberNodeisHTMLLike { +function isNodeHtmlLike(node: FiberNode): node is FiberNodeisHTMLLike { return (typeof node.type === "string") || node.type === null; } -function isNotHtmlLike(node: FiberNode): node is Exclude { - return !isHtmlLike(node); +function isNodeNotHtmlLike(node: FiberNode): node is Exclude { + return !isNodeHtmlLike(node); } -export { isHtmlLike, isNotHtmlLike }; \ No newline at end of file +function isNodeFunctionComponent(node: FiberNode): node is FiberNodeForFunctionComponent { + return isNodeNotHtmlLike(node) && node.stateNode === null; +} + +function isNodeComponentClass(node: FiberNode): node is FiberNodeForComponentClass { + return isNodeNotHtmlLike(node) && (node.stateNode instanceof React.Component); +} + +export { isNodeHtmlLike, isNodeNotHtmlLike, isNodeFunctionComponent, isNodeComponentClass }; \ No newline at end of file