mirror of
https://github.com/bendtherules/react-fiber-traverse.git
synced 2026-08-18 13:52:36 +00:00
Add testcase - utils.isNodeFunctionComponent
This commit is contained in:
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user