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
Copy file name to clipboardExpand all lines: src/content/reference/react/act.md
+39-39Lines changed: 39 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -4,35 +4,35 @@ title: act
4
4
5
5
<Intro>
6
6
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.
8
8
9
9
```js
10
10
awaitact(async actFn)
11
11
```
12
12
13
13
</Intro>
14
14
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.
16
16
17
17
<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()`.
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.
31
31
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).
33
33
34
34
```js {2,4}
35
-
it ('renders with button disabled', async () => {
35
+
it ('merender dengan tombol dinonaktifkan', async () => {
36
36
awaitact(async () => {
37
37
root.render(<TestComponent />)
38
38
});
@@ -42,25 +42,25 @@ it ('renders with button disabled', async () => {
42
42
43
43
<Note>
44
44
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.
46
46
47
-
We will deprecate and remove the sync version in the future.
47
+
Kami akan menonaktifkan dan menghapus versi sinkron di masa mendatang.
48
48
49
49
</Note>
50
50
51
-
#### Parameters {/*parameters*/}
51
+
#### Parameter {/*parameters*/}
52
52
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.
54
54
55
-
#### Returns {/*returns*/}
55
+
#### Kembalian {/*returns*/}
56
56
57
-
`act`does not return anything.
57
+
`act`tidak mengembalikan apa pun.
58
58
59
-
## Usage {/*usage*/}
59
+
## Penggunaan {/*usage*/}
60
60
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.
62
62
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:
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.
113
113
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.
115
115
116
-
### Dispatching events in tests {/*dispatching-events-in-tests*/}
116
+
### Mengirimkan events dalam pengujian {/*dispatching-events-in-tests*/}
117
117
118
-
To test events, wrap the event dispatch inside`act()`:
118
+
Untuk menguji *events*, bungkus pengiriman *events* di dalam`act()`:
119
119
120
120
```js {14,16}
121
121
import {act} from'react';
122
122
importReactDOMfrom'react-dom/client';
123
123
importCounterfrom'./Counter';
124
124
125
-
it.only('can render and update a counter', async () => {
125
+
it.only('dapat me-render dan memperbarui penghitung', async () => {
126
126
constcontainer=document.createElement('div');
127
127
document.body.appendChild(container);
128
128
@@ -137,41 +137,41 @@ it.only('can render and update a counter', async () => {
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.
146
146
147
147
<Pitfall>
148
148
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.
150
150
151
151
</Pitfall>
152
152
153
-
## Troubleshooting {/*troubleshooting*/}
153
+
## Pemecahan Masalah {/*troubleshooting*/}
154
154
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*/}
156
156
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.
158
158
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:
160
160
161
161
<ConsoleBlocklevel="error">
162
162
163
163
Warning: The current testing environment is not configured to support act(...)
164
164
165
165
</ConsoleBlock>
166
166
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:
168
168
169
169
```js
170
170
global.IS_REACT_ACT_ENVIRONMENT=true
171
171
```
172
172
173
173
<Note>
174
174
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
0 commit comments