From 39080755efc8abdac334326887ea678032e7d386 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sat, 10 Aug 2019 09:58:15 +0530 Subject: [PATCH] Add testcase - isNodeComponentClass --- test/utils.isNodeComponentClass.spec.tsx | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test/utils.isNodeComponentClass.spec.tsx diff --git a/test/utils.isNodeComponentClass.spec.tsx b/test/utils.isNodeComponentClass.spec.tsx new file mode 100644 index 0000000..fc3a770 --- /dev/null +++ b/test/utils.isNodeComponentClass.spec.tsx @@ -0,0 +1,63 @@ +// import * as React from "react"; + +// Import stuff from src +import { isNodeComponentClass } 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("isNodeComponentClass", () => { + it("should work for class component", () => { + const C1 = createClassComponent("C1"); + const rootNode = mountAndGetRootNode(C1, container); + + const result = isNodeComponentClass(rootNode); + + expect(result).not.toBeFalsy(); + expect(result).toBe(true); + }); + + it("should not work for function component", () => { + const fn1 = createFunctionComponent("fn1"); + const rootNode = mountAndGetRootNode(fn1, container); + + const result = isNodeComponentClass(rootNode); + + expect(result).toBeFalsy(); + expect(result).toBe(false); + }); + + it("should not work for html like component - div", () => { + const rootNode = mountAndGetRootNode("div", container); + + const result = isNodeComponentClass(rootNode); + + expect(result).toBeFalsy(); + expect(result).toBe(false); + }); + + it("should not work for html like component - svg", () => { + const rootNode = mountAndGetRootNode("svg", container); + + const result = isNodeComponentClass(rootNode); + + expect(result).toBeFalsy(); + expect(result).toBe(false); + }); + }); +});