mirror of
https://github.com/bendtherules/react-fiber-traverse.git
synced 2026-08-18 13:52:36 +00:00
Add testcase - traverse-nested misc
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// import * as PropTypes from "prop-types";
|
||||
import * as React from "react";
|
||||
|
||||
class CDepth2Nested1 extends React.Component {
|
||||
render() {
|
||||
return <CDepth0></CDepth0>;
|
||||
}
|
||||
}
|
||||
|
||||
class CDepth0 extends React.Component {
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default CDepth2Nested1;
|
||||
@@ -0,0 +1,20 @@
|
||||
// import * as PropTypes from "prop-types";
|
||||
import * as React from "react";
|
||||
|
||||
class CDepth3Nested1 extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<CDepth0></CDepth0>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CDepth0 extends React.Component {
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default CDepth3Nested1;
|
||||
@@ -0,0 +1,43 @@
|
||||
// import * as React from "react";
|
||||
|
||||
// Import stuff from src
|
||||
import { traverse } from "../src";
|
||||
|
||||
// Import test helpers and sample components
|
||||
import { mountAndGetRootNode } from "./utils/mount-in-enzyme";
|
||||
import CDepth2Nested1 from "./sample-components/depth-2-nested-1";
|
||||
import CDepth3Nested1 from "./sample-components/depth-3-nested-1";
|
||||
|
||||
describe("traverse", () => {
|
||||
let container: HTMLDivElement;
|
||||
|
||||
beforeEach(() => {
|
||||
container = document.body.appendChild(document.createElement("div"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(container);
|
||||
});
|
||||
|
||||
describe("nested", () => {
|
||||
it("should work for depth=2 with level of nesting=1", () => {
|
||||
const rootNode = mountAndGetRootNode(CDepth2Nested1, container);
|
||||
const mockCallback = jest.fn();
|
||||
|
||||
traverse(rootNode, mockCallback);
|
||||
|
||||
expect(mockCallback.mock.calls.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
it("should work for depth=3 with level of nesting=1", () => {
|
||||
const rootNode = mountAndGetRootNode(CDepth3Nested1, container);
|
||||
const mockCallback = jest.fn();
|
||||
|
||||
traverse(rootNode, mockCallback);
|
||||
|
||||
// Shouldn't count just component depth, should include string nodes
|
||||
expect(mockCallback.mock.calls.length).not.toBe(2);
|
||||
expect(mockCallback.mock.calls.length).toBe(3);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user