Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom. Documentation: https://reactjs.org/docs/test-rend
import {create, act} from 'react-test-renderer'; import App from './app.js'; // The component being tested // 渲染组件 let root; act(() => { root = create(<App value={1}/>) }); // 对根元素进行断言 expect(root.toJSON()).toMatchSnapshot(); // 更新 props act(() => {...
This JSON representation can be later used to recreate ReactCodeMirror component with the same internal state.For example, this is how undo history can be saved in the local storage, so that it remains after the page reloadsimport CodeMirror from '@uiw/react-codemirror'; import { historyField...
importTestRendererfrom'react-test-renderer';functionMyComponent(){return(<div><SubComponent foo="bar"/><p className="my">Hello</p></div>)}functionSubComponent(){return(<p className="sub">Sub</p>);}consttestRenderer=TestRenderer.create(<MyComponent/>);consttestInstance=testRenderer.root;expect...
Rules are objects that represent a single assertion on a component tree. Let's take the link-role-required rule, for example: import { Text } from 'react-native'; const rule: Rule = { id: 'link-role-required', matcher: (node) => isText(node.type), assertion: (node) => { const...