mirror of
https://github.com/bendtherules/react-fiber-traverse.git
synced 2026-08-18 22:01:49 +00:00
Tests - Fix mountAndGetRootNode usage + Add depth=1 test case
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
// import * as PropTypes from "prop-types";
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
class CDepth1 extends React.Component {
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CDepth1;
|
||||||
@@ -7,8 +7,4 @@ class CDepth2 extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// C.propTypes = {
|
|
||||||
// text: PropTypes.string.isRequired
|
|
||||||
// };
|
|
||||||
|
|
||||||
export default CDepth2;
|
export default CDepth2;
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import * as React from "react";
|
// import * as React from "react";
|
||||||
// import ReactDOM from "react-dom";
|
|
||||||
import { mount } from "enzyme";
|
// Import stuff from src
|
||||||
|
import { traverse } from "../src";
|
||||||
|
|
||||||
|
// Import test helpers and sample components
|
||||||
|
import { mountAndGetRootNode } from "./utils/mount-in-enzyme";
|
||||||
|
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 { traverse, FiberNode } from "../src";
|
|
||||||
|
|
||||||
describe("Basic traverse test", () => {
|
describe("Basic traverse test", () => {
|
||||||
let container: HTMLDivElement;
|
let container: HTMLDivElement;
|
||||||
@@ -15,23 +19,23 @@ describe("Basic traverse test", () => {
|
|||||||
document.body.removeChild(container);
|
document.body.removeChild(container);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render correctly", () => {
|
it("should work for depth=1", () => {
|
||||||
const rootRef = React.createRef<CDepth2>();
|
const rootNode = mountAndGetRootNode(CDepth1, container);
|
||||||
|
|
||||||
// ReactDOM.render(
|
|
||||||
// <C text="text" ref={rootRef} />,
|
|
||||||
// document.getElementById("container")
|
|
||||||
// );
|
|
||||||
mount(<CDepth2 ref={rootRef} />, { attachTo: container });
|
|
||||||
|
|
||||||
const mockCallback = jest.fn();
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
if (rootRef.current !== null) {
|
traverse(rootNode, mockCallback);
|
||||||
traverse(
|
|
||||||
(rootRef.current as any)._reactInternalFiber.child as FiberNode,
|
// The mock function is called twice
|
||||||
mockCallback
|
expect(mockCallback.mock.calls.length).toBe(1);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
|
it("should work for depth=2", () => {
|
||||||
|
const rootNode = mountAndGetRootNode(CDepth2, container);
|
||||||
|
|
||||||
|
const mockCallback = jest.fn();
|
||||||
|
|
||||||
|
traverse(rootNode, mockCallback);
|
||||||
|
|
||||||
// The mock function is called twice
|
// The mock function is called twice
|
||||||
expect(mockCallback.mock.calls.length).toBe(2);
|
expect(mockCallback.mock.calls.length).toBe(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user