Skip to content

Commit db63b88

Browse files
committed
Done Translating-addons-test-utils.md
1 parent c397e7d commit db63b88

File tree

1 file changed

+68
-68
lines changed

1 file changed

+68
-68
lines changed

content/docs/addons-test-utils.md

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ layout: docs
66
category: Reference
77
---
88

9-
**Importing**
9+
**استيراد الأدوات**
1010

1111
```javascript
1212
import ReactTestUtils from 'react-dom/test-utils'; // ES6
@@ -15,42 +15,42 @@ var ReactTestUtils = require('react-dom/test-utils'); // ES5 with npm
1515

1616
## Overview {#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 الأداة. [Jest](https://facebook.github.io/jest/) اختبار JavaScript بسهولة. تعلم كيفية البدء مع Jest عبر درس [React درس](https://jestjs.io/docs/tutorial-react) في موقع 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.
25-
26-
- [`act()`](#act)
27-
- [`mockComponent()`](#mockcomponent)
28-
- [`isElement()`](#iselement)
29-
- [`isElementOfType()`](#iselementoftype)
30-
- [`isDOMComponent()`](#isdomcomponent)
31-
- [`isCompositeComponent()`](#iscompositecomponent)
32-
- [`isCompositeComponentWithType()`](#iscompositecomponentwithtype)
33-
- [`findAllInRenderedTree()`](#findallinrenderedtree)
34-
- [`scryRenderedDOMComponentsWithClass()`](#scryrendereddomcomponentswithclass)
35-
- [`findRenderedDOMComponentWithClass()`](#findrendereddomcomponentwithclass)
36-
- [`scryRenderedDOMComponentsWithTag()`](#scryrendereddomcomponentswithtag)
37-
- [`findRenderedDOMComponentWithTag()`](#findrendereddomcomponentwithtag)
38-
- [`scryRenderedComponentsWithType()`](#scryrenderedcomponentswithtype)
39-
- [`findRenderedComponentWithType()`](#findrenderedcomponentwithtype)
40-
- [`renderIntoDocument()`](#renderintodocument)
24+
> أطلقت Airbnb أداة اختبار تُدعى [Enzyme](https://airbnb.io/enzyme/), والتي تجعل من السهل التعامل مع ناتج مكوّناتك. إن قرّرت استخدام أداة اختبار أخرى مع Jest فقد تستحق تجربتها
25+
26+
- [`()act`](#act)
27+
- [`()mockComponent`](#mockcomponent)
28+
- [`()isElement`](#iselement)
29+
- [`()isElementOfType`](#iselementoftype)
30+
- [`()isDOMComponent`](#isdomcomponent)
31+
- [`()isCompositeComponent`](#iscompositecomponent)
32+
- [`()isCompositeComponentWithType`](#iscompositecomponentwithtype)
33+
- [`()findAllInRenderedTree`](#findallinrenderedtree)
34+
- [`()scryRenderedDOMComponentsWithClass`](#scryrendereddomcomponentswithclass)
35+
- [`()findRenderedDOMComponentWithClass`](#findrendereddomcomponentwithclass)
36+
- [`()scryRenderedDOMComponentsWithTag`](#scryrendereddomcomponentswithtag)
37+
- [`()findRenderedDOMComponentWithTag`](#findrendereddomcomponentwithtag)
38+
- [`()scryRenderedComponentsWithType`](#scryrenderedcomponentswithtype)
39+
- [`()findRenderedComponentWithType`](#findrenderedcomponentwithtype)
40+
- [`()renderIntoDocument`](#renderintodocument)
4141
- [`Simulate`](#simulate)
4242

43-
## Reference {#reference}
43+
## مرجع {#reference}
4444

45-
### `act()` {#act}
45+
### `()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 Counter extends React.Component {
@@ -83,7 +83,7 @@ class Counter 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,11 +122,11 @@ 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) لتقليل الشيفرة المتداولة (boilerplate code).
126126

127127
* * *
128128

129-
### `mockComponent()` {#mockcomponent}
129+
### `()mockComponent` {#mockcomponent}
130130

131131
```javascript
132132
mockComponent(
@@ -135,25 +135,25 @@ 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+
تمرير وحدة المكوّن المحاكي إلى هذا التابع لتزويد المكوّن بتوابع مفيدة، فبدلًا من التصيير الاعتيادي سيصبح المكوّن عنصر `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` هي واجهة برمجة تطبيق قديمة. نوصي باستخدام التصيير السطحي أو [التصيير السطحي](/docs/shallow-renderer.html) أو [`jest.mock()`](https://facebook.github.io/jest/docs/en/tutorial-react-native.html#mock-native-modules-using-jestmock) بدلًا من ذلك.
143143
144144
* * *
145145

146-
### `isElement()` {#iselement}
146+
### `()isElement` {#iselement}
147147

148148
```javascript
149149
isElement(element)
150150
```
151151

152-
Returns `true` if `element` is any React element.
152+
يُعيد القيمة `true` إن كان الوسيط `element` عبارة عن عنصر React.
153153

154154
* * *
155155

156-
### `isElementOfType()` {#iselementoftype}
156+
### `()isElementOfType` {#iselementoftype}
157157

158158
```javascript
159159
isElementOfType(
@@ -162,31 +162,31 @@ isElementOfType(
162162
)
163163
```
164164

165-
Returns `true` if `element` is a React element whose type is of a React `componentClass`.
165+
يُعيد القيمة `true` إن كان الوسيط `element` عبارة عن عنصر React نوعه هو `componentClass`.
166166

167167
* * *
168168

169-
### `isDOMComponent()` {#isdomcomponent}
169+
### `()isDOMComponent` {#isdomcomponent}
170170

171171
```javascript
172172
isDOMComponent(instance)
173173
```
174174

175-
Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
175+
يُعيد القيمة `true` إن كان الوسيط `instance` هو مكوّن DOM (مثل `div` أو `span`).
176176

177177
* * *
178178

179-
### `isCompositeComponent()` {#iscompositecomponent}
179+
### `()isCompositeComponent` {#iscompositecomponent}
180180

181181
```javascript
182182
isCompositeComponent(instance)
183183
```
184184

185-
Returns `true` if `instance` is a user-defined component, such as a class or a function.
185+
يُعيد القيمة `true` إن كان الوسيط `instance` عبارة عن مكوّن مُعرَّف من قبل المستخدم كالأصناف أو الدوال.
186186

187187
* * *
188188

189-
### `isCompositeComponentWithType()` {#iscompositecomponentwithtype}
189+
### `()isCompositeComponentWithType` {#iscompositecomponentwithtype}
190190

191191
```javascript
192192
isCompositeComponentWithType(
@@ -195,11 +195,11 @@ isCompositeComponentWithType(
195195
)
196196
```
197197

198-
Returns `true` if `instance` is a component whose type is of a React `componentClass`.
198+
يُعيد القيمة `true` إن كان الوسيط `instance` عبارة عن مكوّن من النوع `componentClass`.
199199

200200
* * *
201201

202-
### `findAllInRenderedTree()` {#findallinrenderedtree}
202+
### `()findAllInRenderedTree` {#findallinrenderedtree}
203203

204204
```javascript
205205
findAllInRenderedTree(
@@ -208,11 +208,11 @@ 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+
التنقل عبر مكوّنات شجرة المكوّنات وجمع كل المكوّنات حيث يكون test(component)‎ قيمته `true`. لا يكون هذا مفيدًا بحد ذاته ولكنّه يُستخدَم كبداية لأدوات اختبار أخرى.
212212

213213
* * *
214214

215-
### `scryRenderedDOMComponentsWithClass()` {#scryrendereddomcomponentswithclass}
215+
### `()scryRenderedDOMComponentsWithClass` {#scryrendereddomcomponentswithclass}
216216

217217
```javascript
218218
scryRenderedDOMComponentsWithClass(
@@ -221,11 +221,11 @@ 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+
إيجاد جميع مكوّنات عناصر DOM في الشجرة المُصيَّرة والتي هي مكوّنات DOM لها اسم صنف يُطابِق المذكور في الوسيط `className`.
225225

226226
* * *
227227

228-
### `findRenderedDOMComponentWithClass()` {#findrendereddomcomponentwithclass}
228+
### `()findRenderedDOMComponentWithClass` {#findrendereddomcomponentwithclass}
229229

230230
```javascript
231231
findRenderedDOMComponentWithClass(
@@ -234,11 +234,11 @@ 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) ولكن يتوقّع وجود نتيجة واحدة، ويُعيد تلك النتيجة، أو يرمي استثناء إن كان عدد المكوّنات المطابقة أكثر من واحد.
238238

239239
* * *
240240

241-
### `scryRenderedDOMComponentsWithTag()` {#scryrendereddomcomponentswithtag}
241+
### `()scryRenderedDOMComponentsWithTag` {#scryrendereddomcomponentswithtag}
242242

243243
```javascript
244244
scryRenderedDOMComponentsWithTag(
@@ -247,11 +247,11 @@ 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+
إيجاد جميع مكوّنات عناصر DOM في الشجرة المُصيَّرة والتي هي مكوّنات DOM لها اسم للوسم يُطابِق المذكور في الوسيط `tagName`.
251251

252252
* * *
253253

254-
### `findRenderedDOMComponentWithTag()` {#findrendereddomcomponentwithtag}
254+
### `()findRenderedDOMComponentWithTag` {#findrendereddomcomponentwithtag}
255255

256256
```javascript
257257
findRenderedDOMComponentWithTag(
@@ -260,11 +260,11 @@ 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) , ولكن يتوقّع وجود نتيجة واحدة، ويُعيد تلك النتيجة، أو يرمي استثناء إن كان عدد المكوّنات المطابقة أكثر من واحد.
264264

265265
* * *
266266

267-
### `scryRenderedComponentsWithType()` {#scryrenderedcomponentswithtype}
267+
### `()scryRenderedComponentsWithType` {#scryrenderedcomponentswithtype}
268268

269269
```javascript
270270
scryRenderedComponentsWithType(
@@ -273,11 +273,11 @@ scryRenderedComponentsWithType(
273273
)
274274
```
275275

276-
Finds all instances of components with type equal to `componentClass`.
276+
إيجاد جميع نسخ المكوّنات التي نوعها يُساوي `componentClass`.
277277

278278
* * *
279279

280-
### `findRenderedComponentWithType()` {#findrenderedcomponentwithtype}
280+
### `()findRenderedComponentWithType` {#findrenderedcomponentwithtype}
281281

282282
```javascript
283283
findRenderedComponentWithType(
@@ -286,30 +286,30 @@ 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) ولكن يتوقّع وجود نتيجة واحدة، ويُعيد تلك النتيجة، أو يرمي استثناء إن كان عدد المكوّنات المطابقة أكثر من واحد.
290290

291291
***
292292

293-
### `renderIntoDocument()` {#renderintodocument}
293+
### `()renderIntoDocument` {#renderintodocument}
294294

295295
```javascript
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.
308+
> تحتاج إلى أن تكون `window`، و `window.document`، و `window.document.createElement` متوفرة لديك بشكل عام (global) قبل استيراد React، وإلّا ستعتقد React أنّها لا تستطيع الوصول إلى DOM ولن تعمل توابع مثل `setState`.
309309
310310
* * *
311311

312-
## Other Utilities {#other-utilities}
312+
## أدوات أخرى {#other-utilities}
313313

314314
### `Simulate` {#simulate}
315315

@@ -320,19 +320,19 @@ Simulate.{eventName}(
320320
)
321321
```
322322

323-
Simulate an event dispatch on a DOM node with optional `eventData` event data.
323+
محاكاة حدث في عقدة DOM مع خيار إضافي لبيانات الأحداث `eventData`.
324324

325-
`Simulate` has a method for [every event that React understands](/docs/events.html#supported-events).
325+
تمتلك الأداة `Simulate` تابعًا [لكل حدث تفهمه React](/docs/events.html#supported-events).
326326

327-
**Clicking an element**
327+
**الضغط على عنصر:**
328328

329329
```javascript
330330
// <button ref={(node) => this.button = node}>...</button>
331331
const node = this.button;
332332
ReactTestUtils.Simulate.click(node);
333333
```
334334

335-
**Changing the value of an input field and then pressing ENTER.**
335+
**تغيير القيمة لحقل الإدخال ثمّ الضغط على `ENTER`:**
336336

337337
```javascript
338338
// <input ref={(node) => this.textInput = node} />
@@ -342,8 +342,8 @@ ReactTestUtils.Simulate.change(node);
342342
ReactTestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which: 13});
343343
```
344344

345-
> Note
345+
> ملاحظة
346346
>
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.
347+
> يجب عليك تزويد أي خاصيّة حدث تستخدمها في مكوّنك (مثل `KeyCode`، و `Which`، إلخ...) لأنّ React لا تُنشِئ أي من هذه الخاصيّات لأجلك.
348348
349349
* * *

0 commit comments

Comments
 (0)