本文整理汇总了TypeScript中react-test-renderer.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
import React = require("react");
import { act, create, ReactTestInstance } from "react-test-renderer";
import { createRenderer } from 'react-test-renderer/shallow';
class TestComponent extends React.Component { }
const renderer = create(React.createElement("div"), {
createNodeMock: (el: React.ReactElement<any>) => {
return {};
}
});
const json = renderer.toJSON();
if (json) {
json.type = "t";
json.props = {
prop1: "p",
};
json.children = [json];
}
const tree = renderer.toTree();
if (tree) {
tree.type = "t";
tree.props = {
prop1: "p",
};
tree.children = [tree];
tree.rendered = tree;
tree.nodeType = "component";
tree.nodeType = "host";
示例2: create
import * as React from "react";
import { create } from "react-test-renderer";
import { createRenderer } from 'react-test-renderer/shallow';
const tree = create(React.createElement("div"), {
createNodeMock: (el: React.ReactElement<any>) => {
return {};
}
}).toJSON();
tree.type = "t";
tree.props = {
prop1: "p",
};
tree.children = [tree];
tree.$$typeof = "t";
class TestComponent extends React.Component { }
const component = React.createElement(TestComponent);
const shallowRenderer = createRenderer();
shallowRenderer.render(component);
shallowRenderer.getRenderOutput();
示例3: callback
export function safeCreate<TProps>(content: React.ReactElement<TProps>, callback: (wrapper: renderer.ReactTestRenderer) => void): void {
const wrapper = renderer.create(content);
callback(wrapper);
wrapper.unmount();
}