Skip to content

Commit 4547fd1

Browse files
Lukereonalregalius
authored andcommitted
Translate Test Utilities Page (#16)
1 parent b74cb23 commit 4547fd1

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

content/docs/addons-test-utils.md

+52-51
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
22
id: test-utils
3-
title: Test Utilities
3+
title: Utilitas Tes
44
permalink: docs/test-utils.html
55
layout: docs
66
category: Reference
77
---
88

9-
**Importing**
9+
**Cara Import**
1010

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

16-
## Overview {#overview}
16+
## Ikhtisar {#ikhtisar}
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` mempermudah kita melakukan tes pada komponen React dengan _framework_ tes pilihan anda. Di Facebook kami menggunakan [Jest](https://facebook.github.io/jest/) untuk tes JavaScript yang tidak merepotkan. Belajar cara mulai menggunakan Jest melalui situs Jest [React Tutorial](https://jestjs.io/docs/tutorial-react).
1919

20-
> Note:
20+
> Catatan:
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+
> Kami menyarankan Anda untuk menggunakan [`react-testing-library`](https://git.io/react-testing-library) yang didesain untuk memfasilitasi dan mendorong penulisan tes yang menggunakan komponen anda selayaknya seorang pengguna sebenarnya.
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+
> Pilihan lain, Airbnb telah merilis utilitas tes bernama [Enzyme](https://airbnb.io/enzyme/), yang mempermudah kita dalam menyatakan, memanipulasi, dan melewati keluaran dari komponen React anda.
2525
2626
- [`act()`](#act)
2727
- [`mockComponent()`](#mockcomponent)
@@ -40,17 +40,17 @@ var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm
4040
- [`renderIntoDocument()`](#renderintodocument)
4141
- [`Simulate`](#simulate)
4242

43-
## Reference {#reference}
43+
## Referensi {#referensi}
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+
Untuk menyiapkan komponen sebelum penegasan, bungkus kode yang me-*render* komponen tersebut dan lakukan pembaruan di dalam panggilan `act()`. Hal ini membuat tes anda berjalan menyerupai bagaimana React bekerja di peramban.
4848

49-
>Note
49+
>Catatan
5050
>
51-
>If you use `react-test-renderer`, it also provides an `act` export that behaves the same way.
51+
>Jika Anda menggunakan `react-test-renderer`, `react-test-renderer` juga menyediakan sebuah `act` ekspor yang sama.
5252
53-
For example, let's say we have this `Counter` component:
53+
Sebagai contoh, katakanlah kita punya `Counter` komponen:
5454

5555
```js
5656
class App extends React.Component {
@@ -60,10 +60,10 @@ class App extends React.Component {
6060
this.handleClick = this.handleClick.bind(this);
6161
}
6262
componentDidMount() {
63-
document.title = `You clicked ${this.state.count} times`;
63+
document.title = `Anda menekan sebanyak ${this.state.count} kali`;
6464
}
6565
componentDidUpdate() {
66-
document.title = `You clicked ${this.state.count} times`;
66+
document.title = `Anda menekan sebanyak ${this.state.count} kali`;
6767
}
6868
handleClick() {
6969
this.setState(state => ({
@@ -73,17 +73,17 @@ class App extends React.Component {
7373
render() {
7474
return (
7575
<div>
76-
<p>You clicked {this.state.count} times</p>
76+
<p>Anda telah menekan sebanyak {this.state.count} kali</p>
7777
<button onClick={this.handleClick}>
78-
Click me
78+
Tekan aku
7979
</button>
8080
</div>
8181
);
8282
}
8383
}
8484
```
8585

86-
Here is how we can test it:
86+
Ini adalah contoh bagaimana kita bisa menguji komponen ini:
8787

8888
```js{3,20-22,29-31}
8989
import React from 'react';
@@ -103,26 +103,26 @@ afterEach(() => {
103103
container = null;
104104
});
105105
106-
it('can render and update a counter', () => {
107-
// Test first render and componentDidMount
106+
it('bisa render dan memperbarui counter', () => {
107+
// Uji render pertama dan componentDidMount
108108
act(() => {
109109
ReactDOM.render(<Counter />, container);
110110
});
111111
const button = container.querySelector('button');
112112
const label = container.querySelector('p');
113-
expect(label.textContent).toBe('You clicked 0 times');
114-
expect(document.title).toBe('You clicked 0 times');
113+
expect(label.textContent).toBe('Anda menekan sebanyak 0 kali');
114+
expect(document.title).toBe('Anda menekan sebanyak 0 kali');
115115
116-
// Test second render and componentDidUpdate
116+
// Uji render kedua dan componentDidUpdate
117117
act(() => {
118118
button.dispatchEvent(new MouseEvent('click', {bubbles: true}));
119119
});
120-
expect(label.textContent).toBe('You clicked 1 times');
121-
expect(document.title).toBe('You clicked 1 times');
120+
expect(label.textContent).toBe('Anda menekan sebanyak 1 kali');
121+
expect(document.title).toBe('Anda menekan sebanyak 1 kali');
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+
Jangan lupa dalam mengirim perihal DOM hanya dapat dilakukan ketika penampung DOM sudah ditambahkan ke `document`. Anda dapat menggunakan penunjang seperti [`react-testing-library`](https://github.com/kentcdodds/react-testing-library) untuk mengurangi kode _boilerplate_.
126126

127127
* * *
128128

@@ -135,11 +135,12 @@ 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+
Oper sebuah komponen tiruan ke _method_ ini untuk menambahkan _method-method_ berguna yang memperbolehkan komponen tersebut untuk digunakan sebagai komponen React tiruan. Sebagai ganti dari _rendering_ seperti biasa, komponen tiruan ini akan menjadi `<div>` sederhana (atau tag lain jika `mockTagName` disediakan) yang menampung anak komponen yang disediakan.
139139

140-
> Note:
140+
> Catatan:
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+
143+
> `mockComponent()` adalah sebuah API peninggalan. Kami menyarankan Anda menggunakan [shallow rendering](/docs/shallow-renderer.html) atau [`jest.mock()`](https://facebook.github.io/jest/docs/en/tutorial-react-native.html#mock-native-modules-using-jestmock).
143144
144145
* * *
145146

@@ -149,7 +150,7 @@ Pass a mocked component module to this method to augment it with useful methods
149150
isElement(element)
150151
```
151152

152-
Returns `true` if `element` is any React element.
153+
Mengembalikan `true` jika `element` adalah sebuah React elemen.
153154

154155
* * *
155156

@@ -162,7 +163,7 @@ isElementOfType(
162163
)
163164
```
164165

165-
Returns `true` if `element` is a React element whose type is of a React `componentClass`.
166+
Mengembalikan `true` jika `element` adalah sebuah React elemen yang memiliki tipe dari React `componentClass`.
166167

167168
* * *
168169

@@ -172,7 +173,7 @@ Returns `true` if `element` is a React element whose type is of a React `compone
172173
isDOMComponent(instance)
173174
```
174175

175-
Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
176+
Mengembalikan `true` jika `instance` adalah sebuah komponen DOM (seperti sebuah `<div>` atau `<span>`).
176177

177178
* * *
178179

@@ -182,7 +183,7 @@ Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
182183
isCompositeComponent(instance)
183184
```
184185

185-
Returns `true` if `instance` is a user-defined component, such as a class or a function.
186+
Mengembalikan `true` jika `instance` adalah sebuah komponen yang ditetapkan oleh pengguna, seperti sebuah kelas atau sebuah fungsi.
186187

187188
* * *
188189

@@ -195,7 +196,7 @@ isCompositeComponentWithType(
195196
)
196197
```
197198

198-
Returns `true` if `instance` is a component whose type is of a React `componentClass`.
199+
Mengembalikan `true` jika `instance` adalah sebuah komponen yang memiliki tipe dari React `componentClass`.
199200

200201
* * *
201202

@@ -208,7 +209,7 @@ findAllInRenderedTree(
208209
)
209210
```
210211

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.
212+
Melewati semua komponen dalam `tree` dan mengumpulkan semua komponen yang `test(component)` adalah `true`. Ini tidak begitu bermanfaat dengan dirinya sendiri, tetapi digunakan sebagai primitif untuk alat uji lainnya.
212213

213214
* * *
214215

@@ -221,7 +222,7 @@ scryRenderedDOMComponentsWithClass(
221222
)
222223
```
223224

224-
Finds all DOM elements of components in the rendered tree that are DOM components with the class name matching `className`.
225+
Mencari semua DOM elemen dalam _rendered tree_ yang merupakan komponen DOM yang memiliki nama kelas sama dengan `className`.
225226

226227
* * *
227228

@@ -234,7 +235,7 @@ findRenderedDOMComponentWithClass(
234235
)
235236
```
236237

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.
238+
Seperti [`scryRenderedDOMComponentsWithClass()`](#scryrendereddomcomponentswithclass) tetapi mengharapkan satu hasil dan mengembalikan satu hasil tersebut atau melempar _exception_ jika ada lebih dari satu yang cocok.
238239

239240
* * *
240241

@@ -247,7 +248,7 @@ scryRenderedDOMComponentsWithTag(
247248
)
248249
```
249250

250-
Finds all DOM elements of components in the rendered tree that are DOM components with the tag name matching `tagName`.
251+
Mencari semua DOM elemen dalam _rendered tree_ yang merupakan komponen DOM dengan nama label yang sama dengan `tagName`.
251252

252253
* * *
253254

@@ -260,7 +261,7 @@ findRenderedDOMComponentWithTag(
260261
)
261262
```
262263

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.
264+
Seperti [`scryRenderedDOMComponentsWithTag()`](#scryrendereddomcomponentswithtag) tetapi mengharapkan satu hasil dan mengembalikan satu hasil tersebut atau melempar _exception_ jika ada lebih dari satu yang cocok.
264265

265266
* * *
266267

@@ -273,7 +274,7 @@ scryRenderedComponentsWithType(
273274
)
274275
```
275276

276-
Finds all instances of components with type equal to `componentClass`.
277+
Mencari semua instansi dari komponen dengan tipe yang sama dengan `componentClass`.
277278

278279
* * *
279280

@@ -286,7 +287,7 @@ findRenderedComponentWithType(
286287
)
287288
```
288289

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.
290+
Sama seperti [`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype) tetapi mengharapkan satu hasil dan mengembalikan satu hasil tersebut atau melempar _exception_ jika ada lebih dari satu yang cocok.
290291

291292
***
292293

@@ -296,16 +297,16 @@ Same as [`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype) bu
296297
renderIntoDocument(element)
297298
```
298299

299-
Render a React element into a detached DOM node in the document. **This function requires a DOM.** It is effectively equivalent to:
300+
Menggambar sebuah elemen React ke dalam sebuah DOM _node_ terpisah dalam _document_. **Fungsi ini membutuhkan sebuah DOM.** Secara efektif hal ini sama dengan:
300301

301302
```js
302303
const domContainer = document.createElement('div');
303304
ReactDOM.render(element, domContainer);
304305
```
305306

306-
> Note:
307+
> Catatan:
307308
>
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+
> Anda harus memiliki `window`, `window.document` dan `window.document.createElement` tersedia secara global **sebelum** Anda import `React`. Jika tidak React akan berpikir tidak dapat mengakses DOM dan _method-method_ seperti `setState` tidak akan bekerja.
309310
310311
* * *
311312

@@ -320,30 +321,30 @@ Simulate.{eventName}(
320321
)
321322
```
322323

323-
Simulate an event dispatch on a DOM node with optional `eventData` event data.
324+
Mensimulasikan pengiriman sebuah perihal pada suatu DOM _node_ dengan pilihan `eventData` _event_ data.
324325

325-
`Simulate` has a method for [every event that React understands](/docs/events.html#supported-events).
326+
`Simulate` memiliki sebuah _method_ untuk [every event that React understands](/docs/events.html#supported-events).
326327

327-
**Clicking an element**
328+
**Klik sebuah elemen**
328329

329330
```javascript
330331
// <button ref={(node) => this.button = node}>...</button>
331332
const node = this.button;
332333
ReactTestUtils.Simulate.click(node);
333334
```
334335

335-
**Changing the value of an input field and then pressing ENTER.**
336+
**Mengubah nilai dari sebuah bidang masukan lalu menekan ENTER.**
336337

337338
```javascript
338339
// <input ref={(node) => this.textInput = node} />
339340
const node = this.textInput;
340-
node.value = 'giraffe';
341+
node.value = 'jerapah';
341342
ReactTestUtils.Simulate.change(node);
342343
ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
343344
```
344345

345-
> Note
346+
> Catatan
346347
>
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.
348+
> Anda harus menyediakan _event_ properti yang Anda gunakan dalam komponen (contoh keyCode, which, dll...) karena React tidak membuat _event_ tersebut untuk Anda.
348349
349350
* * *

0 commit comments

Comments
 (0)