Add getWrappedComponent util and consume in tests

This commit is contained in:
2019-07-25 08:54:17 +05:30
parent 0bf27b7016
commit ae0e39ab80
2 changed files with 15 additions and 9 deletions
+3 -9
View File
@@ -1,5 +1,4 @@
import React from "react";
import * as React from "react";
// Import stuff from src
import { findNodeByComponentName } from "../src";
@@ -7,6 +6,7 @@ import { findNodeByComponentName } from "../src";
import { mountAndGetRootNode } from "./utils/mount-in-enzyme";
import CDepth1 from "./sample-components/depth-1-simple";
import { FiberNodeForComponentClass } from "../src/mocked-types";
import getWrappedComponent from "./utils/getWrappedComponent";
describe("findNodeByComponentName", () => {
let container: HTMLDivElement;
@@ -21,17 +21,11 @@ describe("findNodeByComponentName", () => {
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 WrappedC = getWrappedComponent(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
+12
View File
@@ -0,0 +1,12 @@
import React from "react";
function getWrappedComponent(SomeComponent: React.ElementType) {
class WrappedC extends React.Component {
render() {
return <SomeComponent />;
}
}
return WrappedC;
}
export default getWrappedComponent;