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
16
+
## 概要
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
+
本質的にこのパッケージは、ブラウザや [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](http://facebook.github.io/jest/blog/2016/07/27/jest-14.html).
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.
105
+
渡された React 要素から `TestRenderer`インスタンスを作成します。実際の DOM は使用しませんが、コンポーネントを完全な形でメモリにレンダーするので、アサーションを行うことができます。返されたインスタンスは、次のメソッドとプロパティを持ちます。
106
106
107
107
### `testRenderer.toJSON()`
108
108
109
109
```javascript
110
110
testRenderer.toJSON()
111
111
```
112
112
113
-
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](http://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.
Unmount the in-memory tree, triggering the appropriate lifecycle events.
137
+
メモリ上のツリーをアンマウントし、適切なライフサイクルイベントを発生させます。
138
138
139
139
### `testRenderer.getInstance()`
140
140
141
141
```javascript
142
142
testRenderer.getInstance()
143
143
```
144
144
145
-
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.
Find all descendant test instances with the provided `type`.
193
+
与えられた `type` を持つ全ての子テストインスタンスを検索します。
194
194
195
195
### `testInstance.findAllByProps()`
196
196
197
197
```javascript
198
198
testInstance.findAllByProps(props)
199
199
```
200
200
201
-
Find all descendant test instances with the provided `props`.
201
+
与えられた `props` を持つ全ての子テストインスタンスを検索します。
202
202
203
203
### `testInstance.instance`
204
204
205
205
```javascript
206
206
testInstance.instance
207
207
```
208
208
209
-
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