mirror of
https://github.com/bendtherules/react-fiber-traverse.git
synced 2026-08-18 13:52:36 +00:00
Add testcase - travserse-basic-depth=5
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
// import * as PropTypes from "prop-types";
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
class CDepth5 extends React.Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<span></span>
|
||||||
|
<button></button>
|
||||||
|
<div></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CDepth5;
|
||||||
@@ -7,10 +7,11 @@ import { traverse } from "../src";
|
|||||||
import { mountAndGetRootNode } from "./utils/mount-in-enzyme";
|
import { mountAndGetRootNode } from "./utils/mount-in-enzyme";
|
||||||
import CDepth1 from "./sample-components/depth-1-simple";
|
import CDepth1 from "./sample-components/depth-1-simple";
|
||||||
import CDepth2 from "./sample-components/depth-2-simple";
|
import CDepth2 from "./sample-components/depth-2-simple";
|
||||||
|
import CDepth5 from "./sample-components/depth-5-simple";
|
||||||
|
|
||||||
describe("Basic traverse test", () => {
|
describe("traverse", () => {
|
||||||
let container: HTMLDivElement;
|
let container: HTMLDivElement;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
container = document.body.appendChild(document.createElement("div"));
|
container = document.body.appendChild(document.createElement("div"));
|
||||||
});
|
});
|
||||||
@@ -19,21 +20,34 @@ describe("Basic traverse test", () => {
|
|||||||
document.body.removeChild(container);
|
document.body.removeChild(container);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work for depth=1", () => {
|
describe("basic", () => {
|
||||||
const rootNode = mountAndGetRootNode(CDepth1, container);
|
it("should work for depth=1", () => {
|
||||||
const mockCallback = jest.fn();
|
const rootNode = mountAndGetRootNode(CDepth1, container);
|
||||||
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
traverse(rootNode, mockCallback);
|
traverse(rootNode, mockCallback);
|
||||||
|
|
||||||
expect(mockCallback.mock.calls.length).toBe(1);
|
// Can't be zero, in any case
|
||||||
});
|
expect(mockCallback.mock.calls.length).not.toBe(0);
|
||||||
|
expect(mockCallback.mock.calls.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
it("should work for depth=2", () => {
|
it("should work for depth=2", () => {
|
||||||
const rootNode = mountAndGetRootNode(CDepth2, container);
|
const rootNode = mountAndGetRootNode(CDepth2, container);
|
||||||
const mockCallback = jest.fn();
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
traverse(rootNode, mockCallback);
|
traverse(rootNode, mockCallback);
|
||||||
|
|
||||||
expect(mockCallback.mock.calls.length).toBe(2);
|
expect(mockCallback.mock.calls.length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work for depth=5", () => {
|
||||||
|
const rootNode = mountAndGetRootNode(CDepth5, container);
|
||||||
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
|
traverse(rootNode, mockCallback);
|
||||||
|
|
||||||
|
expect(mockCallback.mock.calls.length).toBe(5);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user