mirror of
https://github.com/bendtherules/react-fiber-traverse.git
synced 2026-08-18 13:52:36 +00:00
Add testcase - depth-7-nested-2 as a more nested case
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// import * as PropTypes from "prop-types";
|
||||
import * as React from "react";
|
||||
|
||||
class CDepth7Nested2 extends React.Component {
|
||||
render() {
|
||||
const someValue = 5;
|
||||
|
||||
return (
|
||||
<div className="abc" data-test={[1, 2, 3, 4, someValue]}>
|
||||
<CDepth4></CDepth4>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CDepth4 extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<button></button>
|
||||
<CDepth1></CDepth1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CDepth1 extends React.Component {
|
||||
render() {
|
||||
return <div></div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default CDepth7Nested2;
|
||||
@@ -7,6 +7,7 @@ import { traverse } from "../src";
|
||||
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";
|
||||
import CDepth7Nested2 from "./sample-components/depth-7-nested-2";
|
||||
|
||||
describe("traverse", () => {
|
||||
let container: HTMLDivElement;
|
||||
@@ -28,16 +29,25 @@ describe("traverse", () => {
|
||||
|
||||
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();
|
||||
it("should work for depth=3 with level of nesting=1", () => {
|
||||
const rootNode = mountAndGetRootNode(CDepth3Nested1, container);
|
||||
const mockCallback = jest.fn();
|
||||
|
||||
traverse(rootNode, mockCallback);
|
||||
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);
|
||||
// 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);
|
||||
});
|
||||
|
||||
it("should work for depth=7 with level of nesting=2", () => {
|
||||
const rootNode = mountAndGetRootNode(CDepth7Nested2, container);
|
||||
const mockCallback = jest.fn();
|
||||
|
||||
traverse(rootNode, mockCallback);
|
||||
|
||||
expect(mockCallback.mock.calls.length).toBe(7);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user