From 933639e0bae5df533c4471290323d6b3c9da01cc Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sat, 10 Aug 2019 01:43:14 +0530 Subject: [PATCH] Add testcase - utils.isNodeFunctionComponent --- test/utils.isNodeFunctionComponent.spec.tsx | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/utils.isNodeFunctionComponent.spec.tsx diff --git a/test/utils.isNodeFunctionComponent.spec.tsx b/test/utils.isNodeFunctionComponent.spec.tsx new file mode 100644 index 0000000..09dbc23 --- /dev/null +++ b/test/utils.isNodeFunctionComponent.spec.tsx @@ -0,0 +1,63 @@ +// import * as React from "react"; + +// Import stuff from src +import { isNodeFunctionComponent } from "../src/utils"; +import { mountAndGetRootNode } from "./utils/mountInEnzyme"; +import { + createFunctionComponent, + createClassComponent +} from "./utils/createComponent"; + +// Import test helpers and sample components + +describe("utils", () => { + let container: HTMLDivElement; + + beforeEach(() => { + container = document.body.appendChild(document.createElement("div")); + }); + + afterEach(() => { + document.body.removeChild(container); + }); + + describe("isNodeFunctionComponent", () => { + it("should work for function component", () => { + const fn1 = createFunctionComponent("fn1"); + const rootNode = mountAndGetRootNode(fn1, container); + + const result = isNodeFunctionComponent(rootNode); + + expect(result).not.toBeFalsy(); + expect(result).toBe(true); + }); + + it("should not work for class component", () => { + const C1 = createClassComponent("C1"); + const rootNode = mountAndGetRootNode(C1, container); + + const result = isNodeFunctionComponent(rootNode); + + expect(result).toBeFalsy(); + expect(result).toBe(false); + }); + + it("should work for html like component - div", () => { + const rootNode = mountAndGetRootNode("div", container); + + const result = isNodeFunctionComponent(rootNode); + + expect(result).toBeFalsy(); + expect(result).toBe(false); + }); + + it("should work for html like component - svg", () => { + const rootNode = mountAndGetRootNode("svg", container); + + const result = isNodeFunctionComponent(rootNode); + + expect(result).toBeFalsy(); + expect(result).toBe(false); + }); + }); +});