Skip to content

Commit c8a9afa

Browse files
committed
remove deprecated content
1 parent 0eee7b6 commit c8a9afa

File tree

4 files changed

+10
-63
lines changed

4 files changed

+10
-63
lines changed

src/content/4/en/part4a.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ module.exports = {
502502
}
503503
```
504504
505-
> The _average_ function uses the array [reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) method. If the method is not familiar to you yet, then now is a good time to watch the first three videos from the [Functional Javascript](https://www.youtube.com/watch?v=BMUiFMZr7vk&list=PL0zVEGEvSaeEd9hlmCXrk5yUyqUag-n84) series on YouTube.
505+
> The _average_ function uses the array [reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) method. If the method is not familiar to you yet, then now is a good time to watch the first three videos from the [Functional JavaScript](https://www.youtube.com/watch?v=BMUiFMZr7vk&list=PL0zVEGEvSaeEd9hlmCXrk5yUyqUag-n84) series on YouTube.
506506
507507
There are a large number of test libraries, or <i>test runners</i>, available for JavaScript.
508508
The old king of test libraries is [Mocha](https://mochajs.org/), which was replaced a few years ago by [Jest](https://jestjs.io/). A newcomer to the libraries is [Vitest](https://vitest.dev/), which bills itself as a new generation of test libraries.
@@ -696,7 +696,7 @@ test('dummy returns one', () => {
696696
const blogs = []
697697

698698
const result = listHelper.dummy(blogs)
699-
assert.strictEqual(result), 1)
699+
assert.strictEqual(result, 1)
700700
})
701701
```
702702
@@ -725,7 +725,7 @@ describe('total likes', () => {
725725

726726
test('when list has only one blog, equals the likes of that', () => {
727727
const result = listHelper.totalLikes(listWithOneBlog)
728-
assert.strictEqual(result), 5)
728+
assert.strictEqual(result, 5)
729729
})
730730
})
731731
```

src/content/4/en/part4b.md

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ Full stack development is <i> extremely hard</i>, that is why I will use all the
997997
- I will keep an eye on the database: does the backend save data there in the right format
998998
- I will progress in small steps
999999
- <i>I will write lots of _console.log_ statements to make sure I understand how the code and the tests behave and to help pinpoint problems</i>
1000-
- If my code does not work, I will not write more code. Instead, I start deleting the code until it works or just return to a state when everything was still working
1000+
- If my code does not work, I will not write more code. Instead, I start deleting the code until it works or just return to a state when everything is still working
10011001
- <i>If a test does not pass, I make sure that the tested functionality for sure works in the application</i>
10021002
- When I ask for help in the course Discord or Telegram channel or elsewhere I formulate my questions properly, see [here](/en/part0/general_info#how-to-get-help-in-discord-telegram) how to ask for help
10031003
@@ -1007,47 +1007,21 @@ Full stack development is <i> extremely hard</i>, that is why I will use all the
10071007
10081008
### Exercises 4.8.-4.12.
10091009
1010-
**NB:** the material uses the [toContain](https://jestjs.io/docs/expect#tocontainitem) matcher in several places to verify that an array contains a specific element. It's worth noting that the method uses the === operator for comparing and matching elements, which means that it is often not well-suited for matching objects. In most cases, the appropriate method for verifying objects in arrays is the [toContainEqual](https://jestjs.io/docs/expect#tocontainequalitem) matcher. However, the model solutions don't check for objects in arrays with matchers, so using the method is not required for solving the exercises.
1011-
10121010
**Warning:** If you find yourself using async/await and <i>then</i> methods in the same code, it is almost guaranteed that you are doing something wrong. Use one or the other and don't mix the two.
10131011
10141012
#### 4.8: Blog List Tests, step 1
10151013
1016-
Use the supertest package for writing a test that makes an HTTP GET request to the <i>/api/blogs</i> URL. Verify that the blog list application returns the correct amount of blog posts in the JSON format.
1014+
Use the SuperTest library for writing a test that makes an HTTP GET request to the <i>/api/blogs</i> URL. Verify that the blog list application returns the correct amount of blog posts in the JSON format.
10171015
10181016
Once the test is finished, refactor the route handler to use the async/await syntax instead of promises.
10191017
10201018
Notice that you will have to make similar changes to the code that were made [in the material](/en/part4/testing_the_backend#test-environment), like defining the test environment so that you can write tests that use separate databases.
10211019
1022-
**NB:** When running the tests, you may run into the following warning:
1023-
1024-
![Warning to read docs on connecting mongoose to jest](../../images/4/8a.png)
1025-
1026-
[One way](https://stackoverflow.com/questions/50687592/jest-and-mongoose-jest-has-detected-opened-handles) to get rid of this is to add to the <i>tests</i> directory a file <i>teardown.js</i> with the following content
1027-
1028-
```js
1029-
module.exports = () => {
1030-
process.exit(0)
1031-
}
1032-
```
1033-
1034-
and by extending the Jest definitions in the <i>package.json</i> as follows
1035-
1036-
```js
1037-
{
1038-
//...
1039-
"jest": {
1040-
"testEnvironment": "node",
1041-
"globalTeardown": "./tests/teardown.js" // highlight-line
1042-
}
1043-
}
1044-
```
1045-
10461020
**NB:** when you are writing your tests **<i>it is better to not execute them all</i>**, only execute the ones you are working on. Read more about this [here](/en/part4/testing_the_backend#running-tests-one-by-one).
10471021
10481022
#### 4.9: Blog List Tests, step 2
10491023
1050-
Write a test that verifies that the unique identifier property of the blog posts is named <i>id</i>, by default the database names the property <i>_id</i>. Verifying the existence of a property is easily done with Jest's [toBeDefined](https://jestjs.io/docs/en/expect#tobedefined) matcher.
1024+
Write a test that verifies that the unique identifier property of the blog posts is named <i>id</i>, by default the database names the property <i>_id</i>.
10511025
10521026
Make the required changes to the code so that it passes the test. The [toJSON](/en/part3/saving_data_to_mongo_db#connecting-the-backend-to-a-database) method discussed in part 3 is an appropriate place for defining the <i>id</i> parameter.
10531027

src/content/4/fi/osa4a.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ Rakennamme tämän osan tehtävissä <i>blogilistasovellusta</i>, jonka avulla k
402402
Kuvitellaan tilanne, jossa saat sähköpostitse seuraavan, yhteen tiedostoon koodatun sovellusrungon:
403403
404404
```js
405-
const http = require('http')
406405
const express = require('express')
407406
const app = express()
408407
const cors = require('cors')
@@ -683,7 +682,7 @@ test('dummy returns one', () => {
683682
const blogs = []
684683

685684
const result = listHelper.dummy(blogs)
686-
assert.strictEqual(result), 1)
685+
assert.strictEqual(result, 1)
687686
})
688687
```
689688
@@ -712,7 +711,7 @@ describe('total likes', () => {
712711

713712
test('when list has only one blog equals the likes of that', () => {
714713
const result = listHelper.totalLikes(listWithOneBlog)
715-
assert.strictEqual(result), 5)
714+
assert.strictEqual(result, 5)
716715
})
717716
})
718717
```

src/content/4/fi/osa4b.md

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,6 @@ Full stack ‑ohjelmointi on <i>todella</i> hankalaa, ja sen takia lupaan hyödy
10001000
10011001
### Tehtävät 4.8.-4.12.
10021002
1003-
**HUOM:** Materiaalissa käytetään muutamaan kertaan matcheria [toContain](https://jestjs.io/docs/expect#tocontainitem) kun tarkastetaan, onko jokin arvo taulukossa. Kannattaa huomata, että metodi käyttää samuuden vertailuun ===-operaattoria ja olioiden kohdalla tämä ei ole useinkaan se mitä halutaan. Parempi vaihtoehto onkin [toContainEqual](https://jestjs.io/docs/expect#tocontainequalitem). Tosin mallivastauksissa ei vertailla kertaakaan olioita matcherien avulla, joten ilmankin selviää varsin hyvin.
1004-
10051003
**Varoitus:** Jos huomaat kirjoittavasi sekaisin async/awaitia ja <i>then</i>-kutsuja, on 99-prosenttisen varmaa, että teet jotain väärin. Käytä siis jompaakumpaa tapaa, älä missään tapauksessa "varalta" molempia.
10061004
10071005
#### 4.8: blogilistan testit, step 1
@@ -1012,35 +1010,11 @@ Kun testi on valmis, refaktoroi operaatio käyttämään promisejen sijaan async
10121010
10131011
Huomaa, että joudut tekemään koodiin [materiaalin tapaan](/osa4/backendin_testaaminen#test-ymparisto) hieman muutoksia (mm. testausympäristön määrittely), jotta saat järkevästi tehtyä omaa tietokantaa käyttäviä API-tason testejä.
10141012
1015-
**HUOM 1:** Testejä suorittaessa törmäät ehkä seuraavaan varoitukseen:
1016-
1017-
![Virheilmotus Mongoose: looks like you're trying to test Mongoose app with Jest's default jsdomain environment.](../../images/4/8a.png)
1018-
1019-
Virheilmoituksesta pääsee eroon muutamallakin tavalla. [Esimerkiksi](https://stackoverflow.com/questions/50687592/jest-and-mongoose-jest-has-detected-opened-handles) lisäämällä hakemistoon <i>tests</i> tiedosto <i>teardown.js</i> jolla on seuraava sisältö
1020-
1021-
```js
1022-
module.exports = () => {
1023-
process.exit(0)
1024-
}
1025-
```
1026-
1027-
ja lajentamalla tiedoston <i>package.json</i> Jestiä koskevaa määrittelyä seuraavasti
1028-
1029-
```js
1030-
{
1031-
//...
1032-
"jest": {
1033-
"testEnvironment": "node"
1034-
"globalTeardown": ".test/teardown.js" // highlight-line
1035-
}
1036-
}
1037-
```
1038-
1039-
**HUOM 2:** Testien kehitysvaiheessa yleensä **<i>ei kannata suorittaa joka kerta kaikkia testejä</i>**, vaan keskittyä yhteen testiin kerrallaan. Katso lisää [täältä](/osa4/backendin_testaaminen#testien-suorittaminen-yksitellen).
1013+
**HUOM:** Testien kehitysvaiheessa yleensä **<i>ei kannata suorittaa joka kerta kaikkia testejä</i>**, vaan keskittyä yhteen testiin kerrallaan. Katso lisää [täältä](/osa4/backendin_testaaminen#testien-suorittaminen-yksitellen).
10401014
10411015
#### 4.9: blogilistan testit, step2
10421016
1043-
Tee testi, joka varmistaa että palautettujen blogien identifioivan kentän tulee olla nimeltään <i>id</i>. Oletusarvoisestihan tietokantaan talletettujen olioiden tunnistekenttä on <i>_id</i>. Olion kentän olemassaolon tarkastaminen onnistuu Jestin matcherillä [toBeDefined](https://jestjs.io/docs/en/expect#tobedefined).
1017+
Tee testi, joka varmistaa että palautettujen blogien identifioivan kentän tulee olla nimeltään <i>id</i>. Oletusarvoisestihan tietokantaan talletettujen olioiden tunnistekenttä on <i>_id</i>.
10441018
10451019
Muuta koodia siten, että testi menee läpi. Osassa 3 käsitelty [toJSON](/osa3/tietojen_tallettaminen_mongo_db_tietokantaan#tietokantaa-kayttava-backend) on sopiva paikka parametrin <i>id</i> määrittelyyn.
10461020

0 commit comments

Comments
 (0)