Skip to content

Commit 468838c

Browse files
docs: translate 'act' (#714)
Co-authored-by: Resi Respati <[email protected]>
1 parent 6559a74 commit 468838c

File tree

1 file changed

+39
-39
lines changed
  • src/content/reference/react

1 file changed

+39
-39
lines changed

src/content/reference/react/act.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ title: act
44

55
<Intro>
66

7-
`act` is a test helper to apply pending React updates before making assertions.
7+
`act` adalah alat bantu pengujian untuk menerapkan pembaruan React yang tertunda sebelum melakukan perbandingan.
88

99
```js
1010
await act(async actFn)
1111
```
1212

1313
</Intro>
1414

15-
To prepare a component for assertions, wrap the code rendering it and performing updates inside an `await act()` call. This makes your test run closer to how React works in the browser.
15+
Untuk mempersiapkan komponen sebelum perbandingan, bungkus kode yang me-*render*-nya dan melakukan pembaruan di dalam panggilan await act(). Ini membuat pengujian Anda lebih mendekati cara kerja React di peramban.
1616

1717
<Note>
18-
You might find using `act()` directly a bit too verbose. To avoid some of the boilerplate, you could use a library like [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), whose helpers are wrapped with `act()`.
18+
Anda mungkin merasa penggunaan `act()` secara langsung agak terlalu bertele-tele. Untuk menghindari beberapa boilerplate, Anda bisa menggunakan pustaka seperti [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), yang alat bantunya sudah dibungkus dengan `act()`.
1919
</Note>
2020

2121

2222
<InlineToc />
2323

2424
---
2525

26-
## Reference {/*reference*/}
26+
## Referensi {/*reference*/}
2727

2828
### `await act(async actFn)` {/*await-act-async-actfn*/}
2929

30-
When writing UI tests, tasks like rendering, user events, or data fetching can be considered as “units” of interaction with a user interface. React provides a helper called `act()` that makes sure all updates related to these “units” have been processed and applied to the DOM before you make any assertions.
30+
Saat menulis pengujian UI, tugas-tugas seperti me-*render*, *events* pengguna, atau pengambilan data dapat dianggap sebagai "unit" interaksi dengan antarmuka pengguna. React menyediakan alat bantu bernama `act()` yang memastikan semua pembaruan terkait "unit" ini telah diproses dan diterapkan ke DOM sebelum Anda melakukan perbandingan apa pun.
3131

32-
The name `act` comes from the [Arrange-Act-Assert](https://wiki.c2.com/?ArrangeActAssert) pattern.
32+
Nama `act` berasal dari pola [Arrange-Act-Assert](https://wiki.c2.com/?ArrangeActAssert).
3333

3434
```js {2,4}
35-
it ('renders with button disabled', async () => {
35+
it ('merender dengan tombol dinonaktifkan', async () => {
3636
await act(async () => {
3737
root.render(<TestComponent />)
3838
});
@@ -42,25 +42,25 @@ it ('renders with button disabled', async () => {
4242

4343
<Note>
4444

45-
We recommend using `act` with `await` and an `async` function. Although the sync version works in many cases, it doesn't work in all cases and due to the way React schedules updates internally, it's difficult to predict when you can use the sync version.
45+
Kami merekomendasikan penggunaan `act` dengan `await` dan fungsi `async`. Meskipun versi sinkron bekerja dalam banyak kasus, ia tidak berfungsi di semua kasus dan karena cara React menjadwalkan pembaruan secara internal, sulit untuk memprediksi kapan Anda dapat menggunakan versi sinkron.
4646

47-
We will deprecate and remove the sync version in the future.
47+
Kami akan menonaktifkan dan menghapus versi sinkron di masa mendatang.
4848

4949
</Note>
5050

51-
#### Parameters {/*parameters*/}
51+
#### Parameter {/*parameters*/}
5252

53-
* `async actFn`: An async function wrapping renders or interactions for components being tested. Any updates triggered within the `actFn`, are added to an internal act queue, which are then flushed together to process and apply any changes to the DOM. Since it is async, React will also run any code that crosses an async boundary, and flush any updates scheduled.
53+
* `async actFn`: Fungsi async yang membungkus *render* atau interaksi untuk komponen yang diuji. Pembaruan yang dipicu dalam `actFn`, ditambahkan ke antrean act internal, yang kemudian dibersihkan bersama untuk memproses dan menerapkan perubahan pada DOM. Karena bersifat async, React juga akan menjalankan kode yang melewati batas async, dan membersihkan pembaruan yang dijadwalkan.
5454

55-
#### Returns {/*returns*/}
55+
#### Kembalian {/*returns*/}
5656

57-
`act` does not return anything.
57+
`act` tidak mengembalikan apa pun.
5858

59-
## Usage {/*usage*/}
59+
## Penggunaan {/*usage*/}
6060

61-
When testing a component, you can use `act` to make assertions about its output.
61+
Saat menguji sebuah komponen, Anda dapat menggunakan `act` untuk membuat perbandingan tentang keluarannya.
6262

63-
For example, let’s say we have this `Counter` component, the usage examples below show how to test it:
63+
Sebagai contoh, misalnya kita memiliki komponen `Counter`, contoh penggunaan di bawah ini menunjukkan cara mengujinya:
6464

6565
```js
6666
function Counter() {
@@ -70,30 +70,30 @@ function Counter() {
7070
}
7171

7272
useEffect(() => {
73-
document.title = `You clicked ${this.state.count} times`;
73+
document.title = `Anda mengklik ${this.state.count} kali`;
7474
}, [count]);
7575

7676
return (
7777
<div>
78-
<p>You clicked {this.state.count} times</p>
78+
<p>Anda mengklik ${this.state.count} kali</p>
7979
<button onClick={this.handleClick}>
80-
Click me
80+
Klik saya
8181
</button>
8282
</div>
8383
)
8484
}
8585
```
8686

87-
### Rendering components in tests {/*rendering-components-in-tests*/}
87+
### Me-*render* komponen dalam pengujian {/*rendering-components-in-tests*/}
8888

89-
To test the render output of a component, wrap the render inside `act()`:
89+
Untuk menguji keluaran *render* suatu komponen, bungkus *render* tersebut di dalam `act()`:
9090

9191
```js {10,12}
9292
import {act} from 'react';
9393
import ReactDOM from 'react-dom/client';
9494
import Counter from './Counter';
9595

96-
it('can render and update a counter', async () => {
96+
it('dapat me-render dan memperbarui penghitung', async () => {
9797
container = document.createElement('div');
9898
document.body.appendChild(container);
9999

@@ -104,25 +104,25 @@ it('can render and update a counter', async () => {
104104

105105
const button = container.querySelector('button');
106106
const label = container.querySelector('p');
107-
expect(label.textContent).toBe('You clicked 0 times');
108-
expect(document.title).toBe('You clicked 0 times');
107+
expect(label.textContent).toBe('Anda mengklik 0 kali');
108+
expect(document.title).toBe('Anda mengklik 0 kali');
109109
});
110110
```
111111

112-
Here, we create a container, append it to the document, and render the `Counter` component inside `act()`. This ensures that the component is rendered and its effects are applied before making assertions.
112+
Di sini, kita membuat sebuah kontainer, menambahkannya ke dalam dokumen, dan me-*render* komponen `Counter` di dalam `act()`. Hal ini memastikan bahwa komponen tersebut di-*render* dan efek-efeknya diterapkan sebelum melakukan perbandingan.
113113

114-
Using `act` ensures that all updates have been applied before we make assertions.
114+
Menggunakan `act` memastikan bahwa semua pembaruan telah diterapkan sebelum kita melakukan perbandingan.
115115

116-
### Dispatching events in tests {/*dispatching-events-in-tests*/}
116+
### Mengirimkan events dalam pengujian {/*dispatching-events-in-tests*/}
117117

118-
To test events, wrap the event dispatch inside `act()`:
118+
Untuk menguji *events*, bungkus pengiriman *events* di dalam `act()`:
119119

120120
```js {14,16}
121121
import {act} from 'react';
122122
import ReactDOM from 'react-dom/client';
123123
import Counter from './Counter';
124124

125-
it.only('can render and update a counter', async () => {
125+
it.only('dapat me-render dan memperbarui penghitung', async () => {
126126
const container = document.createElement('div');
127127
document.body.appendChild(container);
128128

@@ -137,41 +137,41 @@ it.only('can render and update a counter', async () => {
137137

138138
const button = container.querySelector('button');
139139
const label = container.querySelector('p');
140-
expect(label.textContent).toBe('You clicked 1 times');
141-
expect(document.title).toBe('You clicked 1 times');
140+
expect(label.textContent).toBe('Anda mengklik 1 kali');
141+
expect(document.title).toBe('Anda mengklik 1 kali');
142142
});
143143
```
144144

145-
Here, we render the component with `act`, and then dispatch the event inside another `act()`. This ensures that all updates from the event are applied before making assertions.
145+
Di sini, kita me-*render* komponen dengan `act`, dan kemudian mengirimkan *event* ke dalam `act` lainnya. Hal ini memastikan bahwa semua pembaruan dari *event* tersebut diterapkan sebelum melakukan perbandingan.
146146

147147
<Pitfall>
148148

149-
Don’t forget that dispatching DOM events only works when the DOM container is added to the document. You can use a library like [React Testing Library](https://testing-library.com/docs/react-testing-library/intro) to reduce the boilerplate code.
149+
Jangan lupa bahwa mengirimkan *events* DOM hanya berfungsi ketika kontainer DOM ditambahkan ke dalam dokumen. Anda dapat menggunakan pustaka seperti [React Testing Library](https://testing-library.com/docs/react-testing-library/intro) untuk mengurangi kode boilerplate.
150150

151151
</Pitfall>
152152

153-
## Troubleshooting {/*troubleshooting*/}
153+
## Pemecahan Masalah {/*troubleshooting*/}
154154

155-
### I'm getting an error: "The current testing environment is not configured to support act"(...)" {/*error-the-current-testing-environment-is-not-configured-to-support-act*/}
155+
### Saya mendapatkan error: "The current testing environment is not configured to support act(...)" {/*error-the-current-testing-environment-is-not-configured-to-support-act*/}
156156

157-
Using `act` requires setting `global.IS_REACT_ACT_ENVIRONMENT=true` in your test environment. This is to ensure that `act` is only used in the correct environment.
157+
Menggunakan `act` memerlukan pengaturan `global.IS_REACT_ACT_ENVIRONMENT=true` di lingkungan pengujian Anda. Hal ini untuk memastikan bahwa `act` hanya digunakan di lingkungan yang tepat.
158158

159-
If you don't set the global, you will see an error like this:
159+
Jika Anda tidak mengatur global ini, Anda akan melihat error seperti ini:
160160

161161
<ConsoleBlock level="error">
162162

163163
Warning: The current testing environment is not configured to support act(...)
164164

165165
</ConsoleBlock>
166166

167-
To fix, add this to your global setup file for React tests:
167+
Untuk memperbaikinya, tambahkan ini ke *file* pengaturan global untuk pengujian React Anda:
168168

169169
```js
170170
global.IS_REACT_ACT_ENVIRONMENT=true
171171
```
172172

173173
<Note>
174174

175-
In testing frameworks like [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), `IS_REACT_ACT_ENVIRONMENT` is already set for you.
175+
Pada *framework* pengujian seperti [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), `IS_REACT_ACT_ENVIRONMENT` sudah diatur untuk Anda.s
176176

177177
</Note>

0 commit comments

Comments
 (0)