Cleaning out DB after each test

Two questions

After each test I (and I assume everyone else) need to delete anything that was created in MongoDB, so my tests don’t contaminate each other etc.

  1. What’s the best way to empty out the DB?

  2. Is there a way to add a Mocha afterEach() hook so it applies to every test in every file?

I followed the instructions here to reset MongoDB before running tests:

While these instructions were in the Jasmine wiki, this appeared to work with Mocha as well.

The wiki no l longer exists. Could you share how you did it?

try this:

1 Like