DEV Community

Discussion on: Testing Node.js + Mongoose with an in-memory database

Collapse
 
paulasantamaria profile image
Paula Santamaría • Edited

Hi there!
The code I provided in this article clears out the database after every test. If that's not what you want, you can delete the contents of the afterEach function to avoid losing your data after every test.
However, keep in mind that if you're using mongodb-memory-server as your test database, every time you run the tests the database is created from scratch, so you'll have to populate any test data you need before running the tests (I'd do it in the beforeAll function, for example).
Hope this helps!