You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constTestRenderer=require('react-test-renderer'); // ES5 with npm
14
14
```
15
15
16
-
## Overview {#overview}
16
+
## 概览 {#overview}
17
17
18
-
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.
Essentially, this package makes it easy to grab a snapshot of the platform view hierarchy (similar to a DOM tree) rendered by a React DOM or React Native component without using a browser or [jsdom](https://github.com/tmpvar/jsdom).
20
+
这个 package 提供的主要功能是在不依赖浏览器或 [jsdom](https://github.com/tmpvar/jsdom) 的情况下,返回某个时间点由 React DOM 或者 React Native 平台渲染出的视图结构(类似与 DOM 树)快照。
You can use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: [Learn more about it](https://facebook.github.io/jest/blog/2016/07/27/jest-14.html).
41
+
你可以使用 Jest 的快照测试功能来自动保存当前 `JSON` 树结构到一个文件中,并在测试中检查它是否被修改:[了解更多](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html)。
42
42
43
-
You can also traverse the output to find specific nodes and make assertions about them.
Create a `TestRenderer`instance with the passed React element. It doesn't use the real DOM, but it still fully renders the component tree into memory so you can make assertions about it. The returned instance has the following methods and properties.
Return an object representing the rendered tree. This tree only contains the platform-specific nodes like `<div>`or`<View>`and their props, but doesn't contain any user-written components. This is handy for [snapshot testing](https://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
Return an object representing the rendered tree. Unlike `toJSON()`, the representation is more detailed than the one provided by `toJSON()`, and includes the user-written components. You probably don't need this method unless you're writing your own assertion library on top of the test renderer.
Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree.
129
+
使用新的根元素重新渲染内存中的树。它模拟根元素的一次 React 更新。如果新的元素和之前的元素有相同的 type 和 key,该树将会被更新;否则,它将重挂载一个新树。
Return the instance corresponding to the root element, if available. This will not work if the root element is a function component because they don't have instances.
Returns the root "test instance" object that is useful for making assertions about specific nodes in the tree. You can use it to find other "test instances" deeper below.
Find a single descendant test instance for which `test(testInstance)`returns`true`. If `test(testInstance)` does not return `true` for exactly one test instance, it will throw an error.
Find a single descendant test instance with the provided `type`. If there is not exactly one test instance with the provided `type`, it will throw an error.
Find a single descendant test instance with the provided `props`. If there is not exactly one test instance with the provided `props`, it will throw an error.
The component instance corresponding to this test instance. It is only available for class components, as function components don't have instances. It matches the `this`value inside the given component.
0 commit comments