|
1 | | -The test demonstrates one of the temptations a developer meets when writing tests. |
| 1 | +Тест демонстрирует один из соблазнов, с которым сталкиваются разработчики при их написании. |
2 | 2 |
|
3 | | -What we have here is actually 3 tests, but layed out as a single function with 3 asserts. |
| 3 | +У нас тут, по сути, три теста, но они написаны как одна функция с тремя проверками. |
4 | 4 |
|
5 | | -Sometimes it's easier to write this way, but if an error occurs, it's much less obvious what went wrong. |
| 5 | +Иногда так проще писать, но если произойдет ошибка, то гораздо сложнее понять, что пошло не так. |
6 | 6 |
|
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 | +Если ошибка происходит посередине сложного потока выполнения, то нам придётся выяснять, какие данные были в этом месте. По сути, придётся *отлаживать тест*. |
8 | 8 |
|
9 | | -It would be much better to break the test into multiple `it` blocks with clearly written inputs and outputs. |
| 9 | +Гораздо лучше разбить тест на несколько блоков `it` и ясно описать входные и ожидаемые на выходе данные. |
10 | 10 |
|
11 | | -Like this: |
| 11 | +Примерно так: |
12 | 12 | ```js |
13 | | -describe("Raises x to power n", function() { |
14 | | - it("5 in the power of 1 equals 5", function() { |
| 13 | +describe("Возводит x в степень n", function() { |
| 14 | + it("5 в степени 1 будет 5", function() { |
15 | 15 | assert.equal(pow(5, 1), 5); |
16 | 16 | }); |
17 | 17 |
|
18 | | - it("5 in the power of 2 equals 25", function() { |
| 18 | + it("5 в степени 2 будет 25", function() { |
19 | 19 | assert.equal(pow(5, 2), 25); |
20 | 20 | }); |
21 | 21 |
|
22 | | - it("5 in the power of 3 equals 125", function() { |
| 22 | + it("5 в степени 3 будет 125", function() { |
23 | 23 | assert.equal(pow(5, 3), 125); |
24 | 24 | }); |
25 | 25 | }); |
26 | 26 | ``` |
27 | 27 |
|
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 | +Мы заменили один `it` на `describe` и группу блоков `it`. Теперь, если какой-либо из блоков завершится неудачно, мы точно увидим, с какими данными это произошло. |
29 | 29 |
|
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`: |
31 | 31 |
|
32 | 32 |
|
33 | 33 | ```js |
34 | | -describe("Raises x to power n", function() { |
35 | | - it("5 in the power of 1 equals 5", function() { |
| 34 | +describe("Возводит x в степень n", function() { |
| 35 | + it("5 в степени 1 будет 5", function() { |
36 | 36 | assert.equal(pow(5, 1), 5); |
37 | 37 | }); |
38 | 38 |
|
39 | 39 | *!* |
40 | | - // Mocha will run only this block |
41 | | - it.only("5 in the power of 2 equals 25", function() { |
| 40 | + // Mocha будет запускать только этот блок |
| 41 | + it.only("5 в степени 2 будет 25", function() { |
42 | 42 | assert.equal(pow(5, 2), 25); |
43 | 43 | }); |
44 | 44 | */!* |
45 | 45 |
|
46 | | - it("5 in the power of 3 equals 125", function() { |
| 46 | + it("5 в степени 3 будет 125", function() { |
47 | 47 | assert.equal(pow(5, 3), 125); |
48 | 48 | }); |
49 | 49 | }); |
|
0 commit comments