From ae0e39ab80ff49bdaaea6648b1f8c5b2b3e6c645 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Thu, 25 Jul 2019 08:54:17 +0530 Subject: [PATCH] Add getWrappedComponent util and consume in tests --- test/findNodeByName-basic.spec.tsx | 12 +++--------- test/utils/getWrappedComponent.tsx | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 test/utils/getWrappedComponent.tsx diff --git a/test/findNodeByName-basic.spec.tsx b/test/findNodeByName-basic.spec.tsx index 5c72ad3..787ab67 100644 --- a/test/findNodeByName-basic.spec.tsx +++ b/test/findNodeByName-basic.spec.tsx @@ -1,5 +1,4 @@ -import React from "react"; - +import * as React from "react"; // Import stuff from src import { findNodeByComponentName } from "../src"; @@ -7,6 +6,7 @@ import { findNodeByComponentName } from "../src"; import { mountAndGetRootNode } from "./utils/mount-in-enzyme"; import CDepth1 from "./sample-components/depth-1-simple"; import { FiberNodeForComponentClass } from "../src/mocked-types"; +import getWrappedComponent from "./utils/getWrappedComponent"; describe("findNodeByComponentName", () => { let container: HTMLDivElement; @@ -21,17 +21,11 @@ describe("findNodeByComponentName", () => { describe("basic", () => { it("should work for top-level name", () => { - // TODO: Move this to a helper function - class WrappedC extends React.Component { - render() { - return ; - } - } + const WrappedC = getWrappedComponent(CDepth1); const rootNode = mountAndGetRootNode(WrappedC, container); const found = findNodeByComponentName(rootNode, CDepth1.name); - // Shouldn't be null, or other falsy value expect(found).not.toBeFalsy(); expect((found as FiberNodeForComponentClass).stateNode).toBeInstanceOf( CDepth1 diff --git a/test/utils/getWrappedComponent.tsx b/test/utils/getWrappedComponent.tsx new file mode 100644 index 0000000..74eb0db --- /dev/null +++ b/test/utils/getWrappedComponent.tsx @@ -0,0 +1,12 @@ +import React from "react"; + +function getWrappedComponent(SomeComponent: React.ElementType) { + class WrappedC extends React.Component { + render() { + return ; + } + } + return WrappedC; +} + +export default getWrappedComponent; \ No newline at end of file