Skip to content

Commit 3814d78

Browse files
committed
part 4b
1 parent 0217b67 commit 3814d78

File tree

4 files changed

+197
-237
lines changed

4 files changed

+197
-237
lines changed

src/content/4/en/part4a.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ In the next row, the test file imports the function to be tested and assigns it
569569
const reverse = require('../utils/for_testing').reverse
570570
```
571571
572-
Individual test cases are defined with the _test_ function. The first parameter of the function is the test description as a string. The second parameter is a <i>function</i>, that defines the functionality for the test case. The functionality for the second test case looks like this:
572+
Individual test cases are defined with the _test_ function. The first argument of the function is the test description as a string. The second argument is a <i>function</i>, that defines the functionality for the test case. The functionality for the second test case looks like this:
573573
574574
```js
575575
() => {

src/content/4/en/part4b.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ test('the first note is about HTTP methods', async () => {
231231
const response = await api.get('/api/notes')
232232

233233
const contents = response.body.map(e => e.content)
234-
// is the parameter truthy
234+
// is the argument truthy
235235
assert(contents.includes('HTML is easy'))
236236
})
237237
```
@@ -275,7 +275,7 @@ module.exports = {
275275

276276
Testing appears to be easy and our tests are currently passing. However, our tests are bad as they are dependent on the state of the database, that now happens to have two notes. To make them more robust, we have to reset the database and generate the needed test data in a controlled manner before we run the tests.
277277

278-
Our tests are already using the[after](https://nodejs.org/api/test.html#afterfn-options) function of to close the connection to the database after the tests are finished executing. The library Node:test offers many other functions that can be used for executing operations once before any test is run or every time before a test is run.
278+
Our tests are already using the [after](https://nodejs.org/api/test.html#afterfn-options) function of to close the connection to the database after the tests are finished executing. The library node:test offers many other functions that can be used for executing operations once before any test is run or every time before a test is run.
279279

280280
Let's initialize the database <i>before every test</i> with the [beforeEach](https://nodejs.org/api/test.html#beforeeachfn-options) function:
281281

@@ -337,7 +337,7 @@ test('the first note is about HTTP methods', async () => {
337337

338338
The _npm test_ command executes all of the tests for the application. When we are writing tests, it is usually wise to only execute one or two tests.
339339

340-
There are a few different ways of accomplishing this, one of which is the [only](https://nodejs.org/api/test.html#testonlyname-options-fn) method. With the method we can define in the code what tests should be executed:
340+
There are a few different ways of accomplishing this, one of which is the [only](https://nodejs.org/api/test.html#testonlyname-options-fn) method. With this method we can define in the code what tests should be executed:
341341

342342
```js
343343
test.only('notes are returned as json', async () => {
@@ -354,31 +354,31 @@ test.only('there are two notes', async () => {
354354
})
355355
```
356356

357-
When tests are run with option _--test-only_, that is, with the command
357+
When tests are run with option _--test-only_, that is, with the command:
358358

359359
```
360360
npm test -- --test-only
361361
```
362362

363363
only the _only_ marked tests are executed.
364364

365-
The danger of the _only_ is that one forgets to remove those from the code.
365+
The danger of _only_ is that one forgets to remove those from the code.
366366

367-
Another option is to specify the tests that need to be run as parameters of the <i>npm test</i> command.
367+
Another option is to specify the tests that need to be run as arguments of the <i>npm test</i> command.
368368

369369
The following command only runs the tests found in the <i>tests/note_api.test.js</i> file:
370370

371371
```js
372372
npm test -- tests/note_api.test.js
373373
```
374374

375-
The [--tests-by-name-pattern](https://nodejs.org/api/test.html#filtering-tests-by-name) option can be used for running tests with a specific name:
375+
The [--tests-by-name-pattern](https://nodejs.org/api/test.html#filtering-tests-by-name) option can be used for running tests with a specific name:
376376

377377
```js
378378
npm test -- --test-name-pattern="the first note is about HTTP methods"
379379
```
380380

381-
The provided parameter can refer to the name of the test or the describe block. The parameter can also contain just a part of the name. The following command will run all of the tests that contain <i>notes</i> in their name:
381+
The provided argument can refer to the name of the test or the describe block. It can also contain just a part of the name. The following command will run all of the tests that contain <i>notes</i> in their name:
382382

383383
```js
384384
npm run test -- --test-name-pattern="notes"
@@ -960,7 +960,7 @@ beforeEach(async () => {
960960
961961
The solution is quite advanced despite its compact appearance. The _noteObjects_ variable is assigned to an array of Mongoose objects that are created with the _Note_ constructor for each of the notes in the _helper.initialNotes_ array. The next line of code creates a new array that <i>consists of promises</i>, that are created by calling the _save_ method of each item in the _noteObjects_ array. In other words, it is an array of promises for saving each of the items to the database.
962962
963-
The [Promise.all](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) method can be used for transforming an array of promises into a single promise, that will be <i>fulfilled</i> once every promise in the array passed to it as a parameter is resolved. The last line of code <em>await Promise.all(promiseArray)</em> waits until every promise for saving a note is finished, meaning that the database has been initialized.
963+
The [Promise.all](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) method can be used for transforming an array of promises into a single promise, that will be <i>fulfilled</i> once every promise in the array passed to it as an argument is resolved. The last line of code <em>await Promise.all(promiseArray)</em> waits until every promise for saving a note is finished, meaning that the database has been initialized.
964964
965965
> The returned values of each promise in the array can still be accessed when using the Promise.all method. If we wait for the promises to be resolved with the _await_ syntax <em>const results = await Promise.all(promiseArray)</em>, the operation will return an array that contains the resolved values for each promise in the _promiseArray_, and they appear in the same order as the promises in the array.
966966
@@ -1183,7 +1183,7 @@ after(async () => {
11831183
11841184
The test output in the console is grouped according to the <i>describe</i> blocks:
11851185
1186-
![jest output showing grouped describe blocks](../../images/4/7new.png)
1186+
![node:test output showing grouped describe blocks](../../images/4/7new.png)
11871187
11881188
There is still room for improvement, but it is time to move forward.
11891189

src/content/4/es/part4a.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ En la siguiente fila, el archivo de prueba importa la función a ser probada y l
569569
const reverse = require('../utils/for_testing').reverse
570570
```
571571
572-
Los casos de prueba individual se definen con la función _test_. El primer parámetro de la función es la descripción de la prueba como una cadena. El segundo parámetro es una <i>función</i>, que define la funcionalidad para el caso de prueba. La funcionalidad para el segundo caso de prueba se ve así:
572+
Los casos de prueba individual se definen con la función _test_. El primer argumento de la función es la descripción de la prueba como una cadena. El segundo argumento es una <i>función</i>, que define la funcionalidad para el caso de prueba. La funcionalidad para el segundo caso de prueba se ve así:
573573
574574
```js
575575
() => {

0 commit comments

Comments
 (0)