Skip to content

Commit e9a6ac1

Browse files
linhe0x0leviding
authored andcommitted
1-js/03-code-quality/05-testing-mocha (javascript-tutorial#39)
* first draft resolve javascript-tutorial#21 * fix(testing-mocha): Adjust some contents * fix: Adjust some words due to code review changes Signed-off-by: sqrtthree <imsqrtthree@gmail.com> * translate the remaining part * Update article.md
1 parent 6f24971 commit e9a6ac1

File tree

3 files changed

+137
-137
lines changed

3 files changed

+137
-137
lines changed

1-js/03-code-quality/05-testing-mocha/3-pow-test-wrong/solution.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
The test demonstrates one of the temptations a developer meets when writing tests.
1+
这些测试代码演示了开发人员在编写测试代码时遇到的一些疑惑。
22

3-
What we have here is actually 3 tests, but layed out as a single function with 3 asserts.
3+
我们这里实际上有三条测试,但是用了一个函数来放置 3 个断言语句。
44

5-
Sometimes it's easier to write this way, but if an error occurs, it's much less obvious what went wrong.
5+
有时用这种方式编写会更容易,但是如果发生错误,那么出错的情况就不那么明显了。
66

7-
If an error happens inside a complex execution flow, then we'll have to figure out the data at that point. We'll actually have to *debug the test*.
7+
如果在复杂的执行流程中发生了一个错误,那么我们必须在那找出数据。 我们实际上必须**调试测试**
88

9-
It would be much better to break the test into multiple `it` blocks with clearly written inputs and outputs.
9+
将测试分成多个具有明确输入和输出的 `it` 代码块中会更好。
1010

11-
Like this:
11+
像是这样:
1212
```js
1313
describe("Raises x to power n", function() {
1414
it("5 in the power of 1 equals 5", function() {
@@ -25,9 +25,9 @@ describe("Raises x to power n", function() {
2525
});
2626
```
2727

28-
We replaced the single `it` with `describe` and a group of `it` blocks. Now if something fails we would see clearly what the data was.
28+
我们使用 `describe` 和一组 `it` 代码块替换掉了单个的 `it`。现在,如果某个测试失败了,我们会清楚地看到数据是什么。
2929

30-
Also we can isolate a single test and run it in standalone mode by writing `it.only` instead of `it`:
30+
此外,我们可以通过编写`it.only` 而不是 `it` 来隔离单个测试并以独立模式运行它:
3131

3232

3333
```js
@@ -37,7 +37,7 @@ describe("Raises x to power n", function() {
3737
});
3838

3939
*!*
40-
// Mocha will run only this block
40+
// Mocha 将只运行这个代码块
4141
it.only("5 in the power of 2 equals 25", function() {
4242
assert.equal(pow(5, 2), 25);
4343
});

1-js/03-code-quality/05-testing-mocha/3-pow-test-wrong/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# What's wrong in the test?
5+
# 测试代码中有什么错误?
66

7-
What's wrong in the test of `pow` below?
7+
下面测试代码中的 `pow` 有什么错误?
88

99
```js
1010
it("Raises x to the power n", function() {
@@ -21,4 +21,4 @@ it("Raises x to the power n", function() {
2121
});
2222
```
2323

24-
P.S. Syntactically the test is correct and passes.
24+
附:从语法上来说这些测试代码是挣钱和能通过的。

0 commit comments

Comments
 (0)