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: readme-zh-TW.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1041,23 +1041,23 @@ test("Whenever no data is passed, error metric shows zero", () => {
1041
1041
1042
1042
<br/>
1043
1043
1044
-
## ⚪ ️ 3.3 Whenever possible, test with a realistic and fully rendered component
1044
+
## ⚪ ️ 3.3 如果可以,使用真實且完全渲染的組件來進行測試
1045
1045
1046
-
:white_check_mark:**Do:**Whenever reasonably sized, test your component from outside like your users do, fully render the UI, act on it and assert that the rendered UI behaves as expected. Avoid all sort of mocking, partial and shallow rendering - this approach might result in untrapped bugs due to lack of details and harden the maintenance as the tests mess with the internals (see bullet ['Favour blackbox testing'](https://github.com/goldbergyoni/javascript-testing-best-practices#-%EF%B8%8F-14-stick-to-black-box-testing-test-only-public-methods)). If one of the child components is significantly slowing down (e.g. animation) or complicating the setup - consider explicitly replacing it with a fake
With all that said, a word of caution is in order: this technique works for small/medium components that pack a reasonable size of child components. Fully rendering a component with too many children will make it hard to reason about test failures (root cause analysis) and might get too slow. In such cases, write only a few tests against that fat parent component and more tests against its children
1048
+
綜上所說,需要注意的是:這種技術適用於包含合理大小子組件的中小型組件。完全渲染一個有太多子組件的組件會讓他很難被看出失敗的原因 (root cause analysis),而且可能會非常慢。在這種情況下,可以對那些很肥的父組件撰寫少量的測試,並對其子組件多寫幾個測試。
1049
1049
1050
1050
<br/>
1051
1051
1052
-
❌ **Otherwise:**When poking into a component's internal by invoking its private methods, and checking the inner state - you would have to refactor all tests when refactoring the components implementation. Do you really have a capacity for this level of maintenance?
### :clap:Doing It Right Example: Working realistically with a fully rendered component
1060
+
### :clap:正例: 操作一個充分渲染的真實組件
1061
1061
1062
1062

1063
1063
@@ -1075,7 +1075,7 @@ class Calendar extends React.Component {
1075
1075
}
1076
1076
}
1077
1077
1078
-
//Examples use React & Enzyme
1078
+
//Examples use React & Enzyme
1079
1079
test("Realistic approach: When clicked to show filters, filters are displayed", () => {
0 commit comments