Skip to content

Commit 6a4cf1b

Browse files
committed
Add missing chapter about beforeEach and mongoose insertMany method to English material
1 parent e228c95 commit 6a4cf1b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/content/4/en/part4b.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,15 @@ beforeEach(async () => {
972972
973973
The asynchronous nature of JavaScript can lead to surprising behavior, and for this reason, it is important to pay careful attention when using the async/await syntax. Even though the syntax makes it easier to deal with promises, it is still necessary to understand how promises work!
974974
975+
However, there is an even simpler way to implement the _beforeEach_ function. The easiest way to handle the situation is by utilizing Mongoose's built-in method _insertMany_:
976+
977+
```js
978+
beforeEach(async () => {
979+
await Note.deleteMany({})
980+
await Note.insertMany(helper.initialNotes) // highlight-line
981+
})
982+
```
983+
975984
The code for our application can be found on [GitHub](https://github.com/fullstack-hy2020/part3-notes-backend/tree/part4-5), branch <i>part4-5</i>.
976985
977986
### A true full stack developer's oath

src/content/4/fi/osa4b.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ beforeEach(async () => {
964964
965965
JavaScriptin asynkroninen suoritusmalli aiheuttaakin siis helposti yllätyksiä, ja myös async/await-syntaksin kanssa pitää olla koko ajan tarkkana. Vaikka async/await peittää monia promisejen käsittelyyn liittyviä seikkoja, promisejen toiminta on syytä tuntea mahdollisimman hyvin!
966966
967-
Kaikkein helpoimmalla tilanteesta selvitään hyödyntämällä Mongoosen valmista metodia _insertMany_:
967+
On kuitenkin olemassa vieläkin yksinkertaisempi tapa _beforeEach_-funktion toteuttamiseksi. Kaikkein helpoimmalla tilanteesta selvitään hyödyntämällä Mongoosen valmista metodia _insertMany_:
968968
969969
```js
970970
beforeEach(async () => {

0 commit comments

Comments
 (0)