mirror of
https://github.com/bendtherules/react-fiber-traverse.git
synced 2026-08-18 13:52:36 +00:00
Fix test/utils - Allow mounting string type of elements
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { mount } from "enzyme";
|
import { mount } from "enzyme";
|
||||||
import { FiberNode } from '../../src/mocked-types';
|
import { FiberNode } from "../../src/mocked-types";
|
||||||
|
|
||||||
export class RootNodeNotFoundError extends Error {
|
export class RootNodeNotFoundError extends Error {
|
||||||
static message = `Couldn't find root node. This might occur if render has become async`
|
static message = `Couldn't find root node. This might occur if render has become async`;
|
||||||
constructor() {
|
constructor() {
|
||||||
super(RootNodeNotFoundError.message);
|
super(RootNodeNotFoundError.message);
|
||||||
this.name = "RootNodeNotFoundError";
|
this.name = "RootNodeNotFoundError";
|
||||||
@@ -11,7 +11,7 @@ export class RootNodeNotFoundError extends Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function mountAndGetRootNode(
|
export function mountAndGetRootNode(
|
||||||
SomeComponentClass: typeof React.Component,
|
SomeComponentClass: (typeof React.Component) | string,
|
||||||
container: HTMLElement
|
container: HTMLElement
|
||||||
) {
|
) {
|
||||||
const rootRef = React.createRef<React.Component>();
|
const rootRef = React.createRef<React.Component>();
|
||||||
@@ -23,7 +23,8 @@ export function mountAndGetRootNode(
|
|||||||
throw new RootNodeNotFoundError();
|
throw new RootNodeNotFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootNode = ((rootRef.current as any)._reactInternalFiber as FiberNode).child;
|
const rootNode = ((rootRef.current as any)._reactInternalFiber as FiberNode)
|
||||||
|
.child;
|
||||||
|
|
||||||
if (rootNode === null) {
|
if (rootNode === null) {
|
||||||
throw new RootNodeNotFoundError();
|
throw new RootNodeNotFoundError();
|
||||||
|
|||||||
Reference in New Issue
Block a user