Skip to content

Commit 49c75e6

Browse files
committed
Add import for assert to be clear
1 parent 354cb94 commit 49c75e6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/content/4/en/part4b.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ Let's add two notes to the test database using the _mongo.js_ program (here we m
199199
Let's write a few more tests:
200200

201201
```js
202+
const assert = require('node:assert')
203+
// ...
204+
202205
test('there are two notes', async () => {
203206
const response = await api.get('/api/notes')
204207

@@ -211,6 +214,8 @@ test('the first note is about HTTP methods', async () => {
211214
const contents = response.body.map(e => e.content)
212215
assert.strictEqual(contents.includes('HTML is easy'), true)
213216
})
217+
218+
// ...
214219
```
215220

216221
Both tests store the response of the request to the _response_ variable, and unlike the previous test that used the methods provided by _supertest_ for verifying the status code and headers, this time we are inspecting the response data stored in <i>response.body</i> property. Our tests verify the format and content of the response data with the method [strictEqual](https://nodejs.org/docs/latest/api/assert.html#assertstrictequalactual-expected-message) of the assert-library.

src/content/4/fi/osa4b.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ Lisätään tiedoston _mongo.js_ ohjelmaa käyttämällä testitietokantaan kaks
196196
Tehdään pari testiä lisää:
197197

198198
```js
199+
const assert = require('node:assert')
200+
// ...
201+
199202
test('there are two notes', async () => {
200203
const response = await api.get('/api/notes')
201204

@@ -208,6 +211,8 @@ test('the first note is about HTTP methods', async () => {
208211
const contents = response.body.map(e => e.content)
209212
assert.strictEqual(contents.includes('HTML is easy'), true)
210213
})
214+
215+
// ...
211216
```
212217

213218
Molemmat testit sijoittavat pyynnön vastauksen muuttujaan _response_. Toisin kuin edellisessä testissä (joka käytti SuperTestin mekanismeja statuskoodin ja vastauksen headereiden oikeellisuuden varmistamiseen), tällä kertaa tutkitaan vastauksessa olevan datan eli <i>response.body</i>:n oikeellisuutta _assert_-kirjaston [strictEqual](https://nodejs.org/docs/latest/api/assert.html#assertstrictequalactual-expected-message) metodilla.

0 commit comments

Comments
 (0)