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: content/docs/addons-shallow-renderer.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -15,22 +15,22 @@ var ShallowRenderer = require('react-test-renderer/shallow'); // ES5 with npm
15
15
16
16
## Overview {#overview}
17
17
18
-
When writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.
18
+
Khi viết Unit Test cho React, render cạn có thể là cách hữu dụng. Việc render cạn cho phép bạn render một component "sâu một lớp" và xác nhận được sự trung thực của kết quả trả về từ hàm render, mà không cần quan tâm về cách hoạt động của những component con, khi mà chúng không được khởi tạo và render. Việc này không cần dùng DOM.
Shallow testing currently has some limitations, namely not supporting refs.
50
+
Kiểm tra cạn hiện tại vẫn có một vài hạn chế, có thể kể tên là việc chưa hỗ trợ refs.
51
51
52
-
> Note:
52
+
> Lưu ý:
53
53
>
54
-
> We also recommend checking out Enzyme's [Shallow Rendering API](https://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality.
54
+
> Chúng tôi cũng khuyến khích bạn xem thêm về [API Render cạn](https://airbnb.io/enzyme/docs/api/shallow.html) của Enzyme. Nó cung cấp API cấp cao hơn và tốt hơn cho cùng chức năng.
You can think of the shallowRenderer as a "place" to render the component you're testing, and from which you can extract the component's output.
60
+
Bạn có thể tưởng tượng shallowRenderer như là một "nơi" để render component bạn muốn kiểm tra, và từ đó bạn có thể tách đầu ra của component đó.
61
61
62
-
`shallowRenderer.render()`is similar to[`ReactDOM.render()`](/docs/react-dom.html#render) but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented.
62
+
`shallowRenderer.render()`gần giống với[`ReactDOM.render()`](/docs/react-dom.html#render), nhưng nó không cần dùng DOM và chỉ render sâu một lớp. Việc này nghĩa là bạn có thể kiểm tra những component mà không phụ thuộc vào cách những component con được triển khai.
constTestRenderer=require('react-test-renderer'); // ES5 with npm
13
+
constTestRenderer=require('react-test-renderer'); // ES5 với npm
14
14
```
15
15
16
-
## Overview {#overview}
16
+
## Sơ lược {#overview}
17
17
18
-
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.
18
+
Gói này cung cấp một React Renderer để sử dụng cho việc render những React component thành những Javascript object, mà không cần dựa trên DOM hay một môi trường native mobile nào.
19
19
20
-
Essentially, this package makes it easy to grab a snapshot of the platform view hierarchy (similar to a DOM tree) rendered by a React DOM or React Native component without using a browser or[jsdom](https://github.com/tmpvar/jsdom).
20
+
Về bản chất, gói này giúp cho việc chụp một bức tranh toàn cảnh của cấu trúc view (tương tự như cây DOM) được render bởi một component React DOM hay React Native mà không cần tới một trình duyệt hay[jsdom](https://github.com/tmpvar/jsdom).
You can use Jest's snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn't changed: [Learn more about it](https://jestjs.io/docs/en/snapshot-testing).
41
+
Bạn có thể sử dụng chức năng chụp snapshot của Jest để tự động lưu một bản sao của cây JSON vào 1 tập tin và kiểm tra trong những bản thử của bạn rằng nó không thay đổi: [Xem thêm về nó](https://jestjs.io/docs/en/snapshot-testing).
42
42
43
-
You can also traverse the output to find specific nodes and make assertions about them.
43
+
Bạn cũng có thể đi qua đầu ra để tìm những node nhất định và kiểm tra độ chính xác của chúng.
Create a `TestRenderer`instance with the passed React element. It doesn't use the real DOM, but it still fully renders the component tree into memory so you can make assertions about it. The returned instance has the following methods and properties.
106
+
Tạo một instance `TestRenderer`với một element React trong tham số. No kh6ong sử dụng DOM thật, nhưng nó vẫn render cây component một cách đầy đủ vào trong bộ nhớ để bạn có thể kiểm định. Instance được trả về có những hàm và thuộc tính sau đây.
Return an object representing the rendered tree. This tree only contains the platform-specific nodes like `<div>`or`<View>`and their props, but doesn't contain any user-written components. This is handy for [snapshot testing](https://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
144
+
Trả về một object thể hiện cậy được render. Cây này chỉ bao gồm các node riêng cho các nền tảng như `<div>`hay`<View>`và thuộc tính (prop) của chúng, nhưng không bao gồm bất kỳ component do người dùng viết. Việc này tiện cho [thử snapshot](https://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).
145
145
146
146
### `testRenderer.toTree()` {#testrenderertotree}
147
147
148
148
```javascript
149
149
testRenderer.toTree()
150
150
```
151
151
152
-
Return an object representing the rendered tree. Unlike `toJSON()`, the representation is more detailed than the one provided by `toJSON()`, and includes the user-written components. You probably don't need this method unless you're writing your own assertion library on top of the test renderer.
152
+
Trả về một object thể hiện cậy được render. Không như `toJSON()`, sự thể hiện này chi tiết hơn kết quả được cung cấp bởi `toJSON()`, và nó bao gồm cả những component do người dùng viết. Bạn cỏ thể không cần hàm này trừ khi bạn đang viết thư viện kiểm định trên test renderer.
153
153
154
154
### `testRenderer.update()` {#testrendererupdate}
155
155
156
156
```javascript
157
157
testRenderer.update(element)
158
158
```
159
159
160
-
Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree.
160
+
Render lại cây trong bộ nhớ với một element gốc mới. Việc này giả lập một sự cập nhật của React tại gốc. Nếu element mới có cùng loại (type) và key (khoá) với element trước, cây sẽ được cập nhật; nếu không, nó sẽ mount lại một cây mới.
Return the instance corresponding to the root element, if available. This will not work if the root element is a function component because they don't have instances.
176
+
Trả về một instance tương ứng với element gốc, nếu có. Việc này sẽ không hoạt động nếu element gốc là một function component vì nó không có intance.
177
177
178
178
### `testRenderer.root` {#testrendererroot}
179
179
180
180
```javascript
181
181
testRenderer.root
182
182
```
183
183
184
-
Returns the root "test instance" object that is useful for making assertions about specific nodes in the tree. You can use it to find other "test instances" deeper below.
184
+
Trả về object "test instance" gốc hữu dụng cho việc kiểm định những node nhất định trong cây. Bạn có thể dùng nó để tìm những test instance" khác sâu bên dưới.
185
185
186
186
### `testInstance.find()` {#testinstancefind}
187
187
188
188
```javascript
189
189
testInstance.find(test)
190
190
```
191
191
192
-
Find a single descendant test instance for which `test(testInstance)`returns `true`. If`test(testInstance)`does not return`true`for exactly one test instance, it will throw an error.
192
+
Tìm một test instance ngay bên dưới khi `test(testInstance)`trả về `true`. Nếu`test(testInstance)`không trả về`true`cho đúng một test instance, một lỗi sẽ được ném ra.
Find a single descendant test instance with the provided `type`. If there is not exactly one test instance with the provided `type`, it will throw an error.
200
+
Tìm một test instance ngay bên dưới với `type` được cung cấp. Nếu không có chính xác một test instance với `type` được cung cấp, nó sẽ ném ra một lỗi.
Find a single descendant test instance with the provided `props`. If there is not exactly one test instance with the provided `props`, it will throw an error.
208
+
Tìm một test instance ngay bên dưới với `props` được cung cấp. Nếu không có chính xác một test instance với `props` được cung cấp, nó sẽ ném ra một lỗi.
The component instance corresponding to this test instance. It is only available for class components, as function components don't have instances. It matches the `this` value inside the given component.
240
+
Component instance tương ứng với test instance này. Nó chỉ khả dụng cho những class component, vì những function component không có instance. Nó tương đương với giá trị của `this` trong component.
241
241
242
242
### `testInstance.type` {#testinstancetype}
243
243
244
244
```javascript
245
245
testInstance.type
246
246
```
247
247
248
-
The component type corresponding to this test instance. For example, a `<Button />`component has a type of`Button`.
248
+
Loại compoennt tương ứng với test instance này. Vi dụ, một component `<Button />`có loại là`Button`.
249
249
250
250
### `testInstance.props` {#testinstanceprops}
251
251
252
252
```javascript
253
253
testInstance.props
254
254
```
255
255
256
-
The props corresponding to this test instance. For example, a `<Button size="small" />`component has `{size: 'small'}` as props.
256
+
Thuộc tính (props) tương ứng với test instance này. Ví dụ, một component `<Button size="small" />`thì có props là `{size: 'small'}`
0 commit comments