question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blank DB for every single test

See original GitHub issue

I would like to have a clean DB for every single unit test.

I’m using more or less the code from your README. However I’m using beforeEach and afterEach instead of *All. I would have expected the database to be clear after closing the connection in one unit test and creating a new one in the next, but apparently this is not the case.

When rerunning the tests, the first test always starts from a “clean” database. How can I achieve this for every test? At the moment, to achieve what I want, I drop the tables in afterEach, but I’m sure there must be a better approach? You can view me code here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
RusseIIcommented, Nov 5, 2019

I agree and @aymericbouzy I have the same issue. Any ideas on how to fix it?

1reaction
MarcLopezAvilacommented, Nov 10, 2019

Same issue, I moved to mongodb-memory-server and everything works fine.

const startDB = () => new Promise((resolve) => {
  const mongoServer = new MongoMemoryServer();
  mongoServer
    .getConnectionString()
    .then(mongoUri => resolve({
      mongoServer,
      db: MongoDB.connect(mongoUri),
    }));
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing for an Empty Database - LearnHowToProgram.com
As always, we begin by testing the simplest possible behavior. In this case, we'll start with a test to make sure the database...
Read more >
Loopback 4 empty database before a test - Stack Overflow
I want to empty the database before my acceptance test cases. ... It will generate the datasource similar to the last one I...
Read more >
Empty database after test - Laracasts
I thought I've set everything up to use the memory database and don't test against my MySQL database. But after every test my...
Read more >
Database (Data) Testing Tutorial with Sample Test Cases
Database Testing is checking the schema, tables, triggers, etc. of the ... we will look into each type and its sub-types one by...
Read more >
Create an Empty SQL Server Unit Test - Microsoft Learn
The following procedures explain how to create SQL Server unit tests for any database object. SQL Server Data Tools includes some additional ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found