-
Notifications
You must be signed in to change notification settings - Fork 3
/
findNodeByName-basic.spec.tsx
41 lines (33 loc) · 1.14 KB
/
findNodeByName-basic.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from "react";
// Import stuff from src
import { findNodeByComponentName } from "../src";
// Import test helpers and sample components
import { mountAndGetRootNode } from "./utils/mount-in-enzyme";
import CDepth1 from "./sample-components/depth-1-simple";
import { FiberNodeForComponentClass } from "../src/mocked-types";
describe("findNodeByComponentName", () => {
let container: HTMLDivElement;
beforeEach(() => {
container = document.body.appendChild(document.createElement("div"));
});
afterEach(() => {
document.body.removeChild(container);
});
describe("basic", () => {
it("should work for top-level name", () => {
// TODO: Move this to a helper function
class WrappedC extends React.Component {
render() {
return <CDepth1 />;
}
}
const rootNode = mountAndGetRootNode(WrappedC, container);
const found = findNodeByComponentName(rootNode, CDepth1.name);
// Shouldn't be null, or other falsy value
expect(found).not.toBeFalsy();
expect((found as FiberNodeForComponentClass).stateNode).toBeInstanceOf(
CDepth1
);
});
});
});