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
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:
Copy file name to clipboardExpand all lines: src/content/4/en/part4b.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -231,7 +231,7 @@ test('the first note is about HTTP methods', async () => {
231
231
constresponse=awaitapi.get('/api/notes')
232
232
233
233
constcontents=response.body.map(e=>e.content)
234
-
// is the parameter truthy
234
+
// is the argument truthy
235
235
assert(contents.includes('HTML is easy'))
236
236
})
237
237
```
@@ -275,7 +275,7 @@ module.exports = {
275
275
276
276
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.
277
277
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.
279
279
280
280
Let's initialize the database <i>before every test</i> with the [beforeEach](https://nodejs.org/api/test.html#beforeeachfn-options) function:
281
281
@@ -337,7 +337,7 @@ test('the first note is about HTTP methods', async () => {
337
337
338
338
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.
339
339
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:
341
341
342
342
```js
343
343
test.only('notes are returned as json', async () => {
@@ -354,31 +354,31 @@ test.only('there are two notes', async () => {
354
354
})
355
355
```
356
356
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:
358
358
359
359
```
360
360
npm test -- --test-only
361
361
```
362
362
363
363
only the _only_ marked tests are executed.
364
364
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.
366
366
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.
368
368
369
369
The following command only runs the tests found in the <i>tests/note_api.test.js</i> file:
370
370
371
371
```js
372
372
npm test -- tests/note_api.test.js
373
373
```
374
374
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:
376
376
377
377
```js
378
378
npm test ----test-name-pattern="the first note is about HTTP methods"
379
379
```
380
380
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:
382
382
383
383
```js
384
384
npm run test ----test-name-pattern="notes"
@@ -960,7 +960,7 @@ beforeEach(async () => {
960
960
961
961
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.
962
962
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.
964
964
965
965
> 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.
966
966
@@ -1183,7 +1183,7 @@ after(async () => {
1183
1183
1184
1184
The test output in the console is grouped according to the <i>describe</i> blocks:
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í:
0 commit comments