Skip to content

Commit a105561

Browse files
authored
Translation for "Automated testing with Mocha" section (#63)
1 parent cda0fb8 commit a105561

File tree

20 files changed

+264
-264
lines changed

20 files changed

+264
-264
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
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 тести, але вони були описані однією функцією з 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 in the middle of 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
13-
describe("Raises x to power n", function() {
14-
it("5 in the power of 1 equals 5", function() {
13+
describe("Підносить до n-нного степеня", function() {
14+
it("5 піднесене до степеня 1 дорівнює 5", function() {
1515
assert.equal(pow(5, 1), 5);
1616
});
1717

18-
it("5 in the power of 2 equals 25", function() {
18+
it("5 піднесене до степеня 2 дорівнює 25", function() {
1919
assert.equal(pow(5, 2), 25);
2020
});
2121

22-
it("5 in the power of 3 equals 125", function() {
22+
it("5 піднесене до степеня 3 дорівнює 125", function() {
2323
assert.equal(pow(5, 3), 125);
2424
});
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+
Ми замінили один блок `it` на `describe` і групу блоків `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
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() {
3636
assert.equal(pow(5, 1), 5);
3737
});
3838

3939
*!*
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() {
4242
assert.equal(pow(5, 2), 25);
4343
});
4444
*/!*
4545

46-
it("5 in the power of 3 equals 125", function() {
46+
it("5 піднесене до степеня 3 дорівнює 125", function() {
4747
assert.equal(pow(5, 3), 125);
4848
});
4949
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ 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
10-
it("Raises x to the power n", function() {
10+
it("Підносить x до n-нного степеня", function() {
1111
let x = 5;
1212

1313
let result = x;
@@ -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+
P.S. Синтаксичних помилок не має і тести проходять.

1-js/03-code-quality/05-testing-mocha/article.md

Lines changed: 147 additions & 147 deletions
Large diffs are not rendered by default.

1-js/03-code-quality/05-testing-mocha/beforeafter.view/index.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!-- add mocha css, to show results -->
4+
<!-- додаємо css стилі для mocha, щоб вивести результати -->
55
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
6-
<!-- add mocha framework code -->
6+
<!-- додаємо фреймворк mocha до коду -->
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
88
<script>
9-
// enable bdd-style testing
9+
// вмикаємо тестування у bdd стилі
1010
mocha.setup('bdd');
1111
</script>
12-
<!-- add chai -->
12+
<!-- додаємо chai -->
1313
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
1414
<script>
15-
// chai has a lot of stuff, let's make assert global
15+
// chai має багато всього, давайте зробимо assert глобальним
1616
let assert = chai.assert;
1717
</script>
1818
</head>
1919

2020
<body>
2121

22-
<!-- the script with tests (describe, it...) -->
22+
<!-- скрипт з тестами (describe, it...) -->
2323
<script src="test.js"></script>
2424

25-
<!-- the element with id="mocha" will contain test results -->
25+
<!-- елемент з id="mocha" буде містити результати тестів -->
2626
<div id="mocha"></div>
2727

28-
<!-- run tests! -->
28+
<!-- запускаємо тести! -->
2929
<script>
3030
mocha.run();
3131
</script>

1-js/03-code-quality/05-testing-mocha/beforeafter.view/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
describe("test", function() {
22

3-
before(() => alert("Testing startedbefore all tests"));
4-
after(() => alert("Testing finishedafter all tests"));
3+
before(() => alert("Тестування розпочатоперед усіма тестами"));
4+
after(() => alert("Тестування завершенопісля всіх тестів"));
55

6-
beforeEach(() => alert("Before a test – enter a test"));
7-
afterEach(() => alert("After a test – exit a test"));
6+
beforeEach(() => alert("Перед тестом – початок тесту"));
7+
afterEach(() => alert("Після тесту – вихід з тесту"));
88

99
it('test 1', () => alert(1));
1010
it('test 2', () => alert(2));

1-js/03-code-quality/05-testing-mocha/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!-- add mocha css, to show results -->
4+
<!-- додаємо css стилі для mocha, щоб вивести результати -->
55
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
6-
<!-- add mocha framework code -->
6+
<!-- додаємо фреймворк mocha до коду -->
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
88
<script>
9-
mocha.setup('bdd'); // minimal setup
9+
mocha.setup('bdd'); // вмикаємо тестування у bdd стилі
1010
</script>
11-
<!-- add chai -->
11+
<!-- додаємо chai -->
1212
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
1313
<script>
14-
// chai has a lot of stuff, let's make assert global
14+
// chai має багато всього, давайте зробимо assert глобальним
1515
let assert = chai.assert;
1616
</script>
1717
</head>
@@ -20,17 +20,17 @@
2020

2121
<script>
2222
function pow(x, n) {
23-
/* function code is to be written, empty now */
23+
/* код функції треба написати, поки що цей блок пустий */
2424
}
2525
</script>
2626

27-
<!-- the script with tests (describe, it...) -->
27+
<!-- скрипт з тестами (describe, it...) -->
2828
<script src="test.js"></script>
2929

30-
<!-- the element with id="mocha" will contain test results -->
30+
<!-- елемент з id="mocha" буде містити результати тестів -->
3131
<div id="mocha"></div>
3232

33-
<!-- run tests! -->
33+
<!-- запускаємо тести! -->
3434
<script>
3535
mocha.run();
3636
</script>

1-js/03-code-quality/05-testing-mocha/pow-1.view/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!-- add mocha css, to show results -->
4+
<!-- додаємо css стилі для mocha, щоб вивести результати -->
55
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
6-
<!-- add mocha framework code -->
6+
<!-- додаємо фреймворк mocha до коду -->
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
88
<script>
9-
// enable bdd-style testing
9+
// вмикаємо тестування у bdd стилі
1010
mocha.setup('bdd');
1111
</script>
12-
<!-- add chai -->
12+
<!-- додаємо chai -->
1313
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
1414
<script>
15-
// chai has a lot of stuff, let's make assert global
15+
// chai має багато всього, давайте зробимо assert глобальним
1616
let assert = chai.assert;
1717
</script>
1818
</head>
@@ -21,17 +21,17 @@
2121

2222
<script>
2323
function pow(x, n) {
24-
/* function code is to be written, empty now */
24+
/* код функції треба написати, поки що цей блок пустий */
2525
}
2626
</script>
2727

28-
<!-- the script with tests (describe, it...) -->
28+
<!-- скрипт з тестами (describe, it...) -->
2929
<script src="test.js"></script>
3030

31-
<!-- the element with id="mocha" will contain test results -->
31+
<!-- елемент з id="mocha" буде містити результати тестів -->
3232
<div id="mocha"></div>
3333

34-
<!-- run tests! -->
34+
<!-- запускаємо тести! -->
3535
<script>
3636
mocha.run();
3737
</script>

1-js/03-code-quality/05-testing-mocha/pow-1.view/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe("pow", function() {
22

3-
it("raises to n-th power", function() {
3+
it("підносить до n-нного степеня", function() {
44
assert.equal(pow(2, 3), 8);
55
});
66

1-js/03-code-quality/05-testing-mocha/pow-2.view/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!-- add mocha css, to show results -->
4+
<!-- додаємо css стилі для mocha, щоб вивести результати -->
55
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
6-
<!-- add mocha framework code -->
6+
<!-- додаємо фреймворк mocha до коду -->
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
88
<script>
9-
// enable bdd-style testing
9+
// вмикаємо тестування у bdd стилі
1010
mocha.setup('bdd');
1111
</script>
12-
<!-- add chai -->
12+
<!-- додаємо chai -->
1313
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
1414
<script>
15-
// chai has a lot of stuff, let's make assert global
15+
// chai має багато всього, давайте зробимо assert глобальним
1616
let assert = chai.assert;
1717
</script>
1818
</head>
@@ -21,17 +21,17 @@
2121

2222
<script>
2323
function pow(x, n) {
24-
return 8; // :) we cheat!
24+
return 8; // :) це обман!
2525
}
2626
</script>
2727

28-
<!-- the script with tests (describe, it...) -->
28+
<!-- скрипт з тестами (describe, it...) -->
2929
<script src="test.js"></script>
3030

31-
<!-- the element with id="mocha" will contain test results -->
31+
<!-- елемент з id="mocha" буде містити результати тестів -->
3232
<div id="mocha"></div>
3333

34-
<!-- run tests! -->
34+
<!-- запускаємо тести! -->
3535
<script>
3636
mocha.run();
3737
</script>

1-js/03-code-quality/05-testing-mocha/pow-2.view/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
describe("pow", function() {
22

3-
it("2 raised to power 3 is 8", function() {
3+
it("2 піднесене до степеня 3 дорівнює 8", function() {
44
assert.equal(pow(2, 3), 8);
55
});
66

7-
it("3 raised to power 4 is 81", function() {
7+
it("3 піднесене до степеня 4 дорівнює 81", function() {
88
assert.equal(pow(3, 4), 81);
99
});
1010

0 commit comments

Comments
 (0)