Skip to content

Commit e73ac76

Browse files
takanoripsmikitky
authored andcommitted
Translate test-utils (#57)
* add translation * fix lint * Update translation * Update addons-test-utils.md * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * Update addons-test-utils.md * Update addons-test-utils.md * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * Update content/docs/addons-test-utils.md Co-Authored-By: takanorip <[email protected]> * fix lint * fix test utils
1 parent 3bbb186 commit e73ac76

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

content/docs/addons-test-utils.md

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
22
id: test-utils
3-
title: Test Utilities
3+
title: テストユーティリティ
44
permalink: docs/test-utils.html
55
layout: docs
66
category: Reference
77
---
88

9-
**Importing**
9+
**インポート**
1010

1111
```javascript
1212
import ReactTestUtils from 'react-dom/test-utils'; // ES6
1313
var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm
1414
```
1515

16-
## Overview {#overview}
16+
## 概要 {#overview}
1717

18-
`ReactTestUtils` makes it easy to test React components in the testing framework of your choice. At Facebook we use [Jest](https://facebook.github.io/jest/) for painless JavaScript testing. Learn how to get started with Jest through the Jest website's [React Tutorial](https://jestjs.io/docs/tutorial-react).
18+
`ReactTestUtils` はお好みのテストフレームワークで React コンポーネントをテストしやすくするものです。Facebook では快適に JavaScript をテストするために [Jest](https://facebook.github.io/jest/) を使用しています。Jest のウェブサイトにある [React Tutorial](http://facebook.github.io/jest/docs/en/tutorial-react.html#content) を通して Jest の始め方を学んでください。
1919

20-
> Note:
20+
> 補足:
2121
>
22-
> We recommend using [`react-testing-library`](https://git.io/react-testing-library) which is designed to enable and encourage writing tests that use your components as the end users do.
22+
> [`react-testing-library`](https://git.io/react-testing-library) の使用をおすすめします。これは、エンドユーザーがコンポーネントを使用するのと同様の書き方でコンポーネントを使用するテストを書くことを可能にし、かつそれを促進するように設計されています。
2323
>
24-
> Alternatively, Airbnb has released a testing utility called [Enzyme](https://airbnb.io/enzyme/), which makes it easy to assert, manipulate, and traverse your React Components' output.
24+
> また別の手段として、Airbnb [Enzyme](http://airbnb.io/enzyme/) と呼ばれるテストユーティリティをリリースしています。Enzyme は React コンポーネントの出力のアサート、操作、そして横断的な処理を簡単にしてくれます。
2525
2626
- [`act()`](#act)
2727
- [`mockComponent()`](#mockcomponent)
@@ -44,13 +44,13 @@ var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm
4444

4545
### `act()` {#act}
4646

47-
To prepare a component for assertions, wrap the code rendering it and performing updates inside an `act()` call. This makes your test run closer to how React works in the browser.
47+
アサーション用のコンポーネントを準備するために、それをレンダーして更新を実行するコードを `act()` でラップします。これにより、テストはブラウザでの React の動作により近い状態で実行されます。
4848

49-
>Note
49+
>補足
5050
>
51-
>If you use `react-test-renderer`, it also provides an `act` export that behaves the same way.
51+
>`react-test-renderer` を使っている場合、それはこのメソッドと同じように振舞う `act` エクスポートも提供します。
5252
53-
For example, let's say we have this `Counter` component:
53+
例えば、次のような `Counter` コンポーネントがあるとしましょう:
5454

5555
```js
5656
class App extends React.Component {
@@ -83,7 +83,7 @@ class App extends React.Component {
8383
}
8484
```
8585

86-
Here is how we can test it:
86+
これをテストするには次のように書きます:
8787

8888
```js{3,20-22,29-31}
8989
import React from 'react';
@@ -122,7 +122,7 @@ it('can render and update a counter', () => {
122122
});
123123
```
124124

125-
Don't forget that dispatching DOM events only works when the DOM container is added to the `document`. You can use a helper like [`react-testing-library`](https://github.com/kentcdodds/react-testing-library) to reduce the boilerplate code.
125+
DOM イベントのディスパッチは、DOM コンテナが `document` に追加されたときだけ動作することを忘れないでください。[`react-testing-library`]https://github.com/kentcdodds/react-testing-library のようなヘルパーを使えばボイラープレートのコードを減らせます。
126126

127127
* * *
128128

@@ -135,11 +135,11 @@ mockComponent(
135135
)
136136
```
137137

138-
Pass a mocked component module to this method to augment it with useful methods that allow it to be used as a dummy React component. Instead of rendering as usual, the component will become a simple `<div>` (or other tag if `mockTagName` is provided) containing any provided children.
138+
モック化されたコンポーネントモジュールをこのメソッドに渡すことで、ダミーの React コンポーネントとして使用できるようになる便利なメソッドを追加することができます。通常のレンダーの代わりに、コンポーネントは、与えられた子要素を含んだシンプルな `<div>`(もしくは `mockTagName` が与えられていれば他のタグ)になります。
139139

140-
> Note:
140+
> 補足:
141141
>
142-
> `mockComponent()` is a legacy API. We recommend using [shallow rendering](/docs/shallow-renderer.html) or [`jest.mock()`](https://facebook.github.io/jest/docs/en/tutorial-react-native.html#mock-native-modules-using-jestmock) instead.
142+
> `mockComponent()` はレガシーな API です。その代わりとして [shallow rendering](/docs/test-utils.html#shallow-rendering) [`jest.mock()`](https://facebook.github.io/jest/docs/en/tutorial-react-native.html#mock-native-modules-using-jestmock) の使用をおすすめします。
143143
144144
* * *
145145

@@ -149,7 +149,7 @@ Pass a mocked component module to this method to augment it with useful methods
149149
isElement(element)
150150
```
151151

152-
Returns `true` if `element` is any React element.
152+
`element` が任意の React 要素である場合 `true` を返します。
153153

154154
* * *
155155

@@ -162,7 +162,7 @@ isElementOfType(
162162
)
163163
```
164164

165-
Returns `true` if `element` is a React element whose type is of a React `componentClass`.
165+
`element``componentClass` 型の React 要素である場合 `true` を返します。
166166

167167
* * *
168168

@@ -172,7 +172,7 @@ Returns `true` if `element` is a React element whose type is of a React `compone
172172
isDOMComponent(instance)
173173
```
174174

175-
Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
175+
`instance` DOM コンポーネント(`<div>` `<span>` など)である場合 `true` を返します。
176176

177177
* * *
178178

@@ -182,7 +182,7 @@ Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
182182
isCompositeComponent(instance)
183183
```
184184

185-
Returns `true` if `instance` is a user-defined component, such as a class or a function.
185+
`instance` がクラスや関数のようなユーザ定義のコンポーネントである場合 `true` を返します。
186186

187187
* * *
188188

@@ -195,7 +195,7 @@ isCompositeComponentWithType(
195195
)
196196
```
197197

198-
Returns `true` if `instance` is a component whose type is of a React `componentClass`.
198+
`instance` が React の `componentClass` 型のコンポーネントである場合 `true` を返します。
199199

200200
* * *
201201

@@ -208,7 +208,7 @@ findAllInRenderedTree(
208208
)
209209
```
210210

211-
Traverse all components in `tree` and accumulate all components where `test(component)` is `true`. This is not that useful on its own, but it's used as a primitive for other test utils.
211+
`tree` 中のすべてのコンポーネントを横断して `test(component)` `true` である全てのコンポーネントを集め、その結果を返します。このメソッド自身はそれほど有用ではありませんが、他のテストユーティリティのための基本メソッドとして使用されます。
212212

213213
* * *
214214

@@ -221,7 +221,7 @@ scryRenderedDOMComponentsWithClass(
221221
)
222222
```
223223

224-
Finds all DOM elements of components in the rendered tree that are DOM components with the class name matching `className`.
224+
レンダーされたツリー内に存在する、クラス名が `className` に一致する DOM コンポーネントが持つ全ての DOM 要素を探し、その結果を返します。
225225

226226
* * *
227227

@@ -234,7 +234,7 @@ findRenderedDOMComponentWithClass(
234234
)
235235
```
236236

237-
Like [`scryRenderedDOMComponentsWithClass()`](#scryrendereddomcomponentswithclass) but expects there to be one result, and returns that one result, or throws exception if there is any other number of matches besides one.
237+
[`scryRenderedDOMComponentsWithClass()`](#scryrendereddomcomponentswithclass) と同様のメソッドですが、このメソッドは結果が 1 つだけであることを期待しており、その 1 つの結果を返すか、一致するものが 1 つでなかった場合には例外をスローします。
238238

239239
* * *
240240

@@ -247,7 +247,7 @@ scryRenderedDOMComponentsWithTag(
247247
)
248248
```
249249

250-
Finds all DOM elements of components in the rendered tree that are DOM components with the tag name matching `tagName`.
250+
レンダリングされたツリー内に存在する、タグ名が `tagName` に一致する DOM コンポーネントが持つ全ての DOM 要素を探し、その結果を返します。
251251

252252
* * *
253253

@@ -260,7 +260,7 @@ findRenderedDOMComponentWithTag(
260260
)
261261
```
262262

263-
Like [`scryRenderedDOMComponentsWithTag()`](#scryrendereddomcomponentswithtag) but expects there to be one result, and returns that one result, or throws exception if there is any other number of matches besides one.
263+
[`scryRenderedDOMComponentsWithTag()`](#scryrendereddomcomponentswithtag) と同様のメソッドですが、このメソッドは結果が 1 つだけであることを期待しており、その 1 つの結果を返すか、一致するものが 1 つでなかった場合には例外を返します。
264264

265265
* * *
266266

@@ -273,7 +273,7 @@ scryRenderedComponentsWithType(
273273
)
274274
```
275275

276-
Finds all instances of components with type equal to `componentClass`.
276+
型が `componentClass` と同じコンポーネントのインスタンスを全て探し、その結果を返します。
277277

278278
* * *
279279

@@ -286,7 +286,7 @@ findRenderedComponentWithType(
286286
)
287287
```
288288

289-
Same as [`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype) but expects there to be one result and returns that one result, or throws exception if there is any other number of matches besides one.
289+
[`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype) と同様のメソッドですが、このメソッドは結果が 1 つだけであることを期待しており、その 1 つの結果を返すか、一致するものが 1 つでなかった場合には例外を返します。
290290

291291
***
292292

@@ -296,20 +296,19 @@ Same as [`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype) bu
296296
renderIntoDocument(element)
297297
```
298298

299-
Render a React element into a detached DOM node in the document. **This function requires a DOM.** It is effectively equivalent to:
299+
React 要素をドキュメントから切り離された DOM ノードにレンダーします。**この関数を実行するには DOM が必要です。**これは以下のコードと実質的に等価です:
300300

301301
```js
302302
const domContainer = document.createElement('div');
303303
ReactDOM.render(element, domContainer);
304304
```
305305

306-
> Note:
306+
> 補足:
307307
>
308-
> You will need to have `window`, `window.document` and `window.document.createElement` globally available **before** you import `React`. Otherwise React will think it can't access the DOM and methods like `setState` won't work.
309-
308+
> React をインポートする****`window`, `window.document` および `window.document.createElement` をグローバルスコープに持っている必要があります。そうでなければ React は DOM にアクセスできないものと判断し `setState` のようなメソッドが動作しなくなります。
310309
* * *
311310

312-
## Other Utilities {#other-utilities}
311+
## その他のユーティリティ {#other-utilities}
313312

314313
### `Simulate` {#simulate}
315314

@@ -320,19 +319,19 @@ Simulate.{eventName}(
320319
)
321320
```
322321

323-
Simulate an event dispatch on a DOM node with optional `eventData` event data.
322+
省略可能な `eventData` イベントデータを使って DOM ノード上のイベントディスパッチをシミュレートします。
324323

325-
`Simulate` has a method for [every event that React understands](/docs/events.html#supported-events).
324+
`Simulate` [React が理解している全てのイベント](/docs/events.html#supported-events)それぞれに対応するメソッドを持っています。
326325

327-
**Clicking an element**
326+
**要素をクリックする**
328327

329328
```javascript
330329
// <button ref={(node) => this.button = node}>...</button>
331330
const node = this.button;
332331
ReactTestUtils.Simulate.click(node);
333332
```
334333

335-
**Changing the value of an input field and then pressing ENTER.**
334+
**入力フィールドの値を変更して ENTER キーを押す**
336335

337336
```javascript
338337
// <input ref={(node) => this.textInput = node} />
@@ -342,8 +341,8 @@ ReactTestUtils.Simulate.change(node);
342341
ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
343342
```
344343

345-
> Note
344+
> 補足
346345
>
347-
> You will have to provide any event property that you're using in your component (e.g. keyCode, which, etc...) as React is not creating any of these for you.
346+
> React はコンポーネントで使用しているイベントプロパティ(例えば keyCodewhich など)を何も作成しないため、あなたはそれらを Simulate が持つメソッドに渡す必要があります。
348347
349348
* * *

0 commit comments

Comments
 (0)