From c5adcb31528a35ec58a92b636fd95d56274c1882 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sat, 10 Aug 2019 10:49:33 +0530 Subject: [PATCH] Add testcase - utils.isConstructorHtmlLike --- test/utils.isConstructorHtmlLike.spec.tsx | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/utils.isConstructorHtmlLike.spec.tsx diff --git a/test/utils.isConstructorHtmlLike.spec.tsx b/test/utils.isConstructorHtmlLike.spec.tsx new file mode 100644 index 0000000..fbe70f1 --- /dev/null +++ b/test/utils.isConstructorHtmlLike.spec.tsx @@ -0,0 +1,74 @@ +// import * as React from "react"; + +// Import stuff from src +import { isConstructorHtmlLike } from "../src/utils"; +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("isConstructorHtmlLike", () => { + it("should work for string", () => { + const resultPositive = isConstructorHtmlLike("div"); + + expect(resultPositive).not.toBeFalsy(); + expect(resultPositive).toBe(true); + }); + + it("should work for null", () => { + const resultPositive = isConstructorHtmlLike(null); + + expect(resultPositive).not.toBeFalsy(); + expect(resultPositive).toBe(true); + }); + + it("should not work for any function", () => { + const fn1 = function() {}; + + const resultNegative = isConstructorHtmlLike(fn1 as any); + + expect(resultNegative).toBeFalsy(); + expect(resultNegative).toBe(false); + }); + + it("should not work for function components", () => { + const fn1 = createFunctionComponent(); + + const resultNegative = isConstructorHtmlLike(fn1); + + expect(resultNegative).toBeFalsy(); + expect(resultNegative).toBe(false); + }); + + it("should not work for any class", () => { + const C1 = class {}; + + const resultNegative = isConstructorHtmlLike(C1 as any); + + expect(resultNegative).toBeFalsy(); + expect(resultNegative).toBe(false); + }); + + it("should not work for class components", () => { + const C1 = createClassComponent("C1"); + + const resultNegative = isConstructorHtmlLike(C1); + + expect(resultNegative).toBeFalsy(); + expect(resultNegative).toBe(false); + }); + }); +});