From 9039ab991b594df042bbc6b29c4c27aaa2760ae0 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Tue, 23 Jul 2019 15:49:19 +0530 Subject: [PATCH] Add testcase - findNodeByName - one test --- test/findNodeByName-basic.spec.tsx | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/findNodeByName-basic.spec.tsx diff --git a/test/findNodeByName-basic.spec.tsx b/test/findNodeByName-basic.spec.tsx new file mode 100644 index 0000000..5c72ad3 --- /dev/null +++ b/test/findNodeByName-basic.spec.tsx @@ -0,0 +1,41 @@ +import React from "react"; + +// Import stuff from src +import { findNodeByComponentName } from "../src"; + +// Import test helpers and sample components +import { mountAndGetRootNode } from "./utils/mount-in-enzyme"; +import CDepth1 from "./sample-components/depth-1-simple"; +import { FiberNodeForComponentClass } from "../src/mocked-types"; + +describe("findNodeByComponentName", () => { + let container: HTMLDivElement; + + beforeEach(() => { + container = document.body.appendChild(document.createElement("div")); + }); + + afterEach(() => { + document.body.removeChild(container); + }); + + describe("basic", () => { + it("should work for top-level name", () => { + // TODO: Move this to a helper function + class WrappedC extends React.Component { + render() { + return ; + } + } + 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 + ); + }); + }); +});