-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcase - findNodeByName - one test
- Loading branch information
1 parent
68a5080
commit 9039ab9
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
); | ||
}); | ||
}); | ||
}); |