title: JestJs TestSuite is not creating a Database using a mongoose
body: <p>I am using jestjs for the first time and have the following issue. Please see the ISSUE tag.</p>
  
  <p><strong>Below is the code</strong></p>
  
  <pre><code>const request = require('supertest');
  const { app } = require('../src/app');
  const { User } = require('../src/models/user');
  
  const userOne = {
    name: 'Mike',
    age: 45,
    email: 'Mike1@gmail.com',
    password: '5689@wWe',
  };
  
  beforeEach(async () =&gt; {
    await User.deleteMany();
    await new User(userOne).save();
  });
  
  // afterEach(() =&gt; {
  //   console.log('after Each');
  // });
  
  test('Should signup a new user', async () =&gt; {
    await request(app).post('/users').send(userOne).expect(201);
  });
  
  test('Should signin a user', async () =&gt; {
    await request(app)
      .post('/users/login')
      .send({
        email: userOne.email,
        password: userOne.password,
      })
      .expect(200);
  });
  
  test('Should not login non existent user', async () =&gt; {
    await request(app)
      .post('/users/login')
      .send({
        email: userOne.email,
        password: '5689@wWe1',
      })
      .expect(400);
  });
  </code></pre>
  
  <p><strong>Here is my package.json file</strong></p>
  
  <pre><code>{
    "name": "mongodb-promises",
    "version": "1.0.0",
    "description": "",
    "main": "src/index.js",
    "scripts": {
      "start": "node src/index.js",
      "dev": "env-cmd -f ./config/dev.env nodemon src/index.js",
      "test": "env-cmd -f ./config/dev.env jest --watch"
    },
    "jest": {
      "testEnvironment": "node"
    },
    "author": "Nagendra Babu",
    "license": "ISC",
    "dependencies": {
      "@sendgrid/mail": "^7.1.1",
      "bcryptjs": "^2.4.3",
      "body-parser": "^1.19.0",
      "express": "^4.17.1",
      "jsonwebtoken": "^8.5.1",
      "mongodb": "^3.5.7",
      "mongoose": "^5.9.16",
      "mongoose-auto-increment": "^5.0.1",
      "multer": "^1.4.2",
      "sharp": "^0.25.3",
      "validator": "^13.0.0"
    },
    "devDependencies": {
      "env-cmd": "^10.1.0",
      "jest": "^26.0.1",
      "supertest": "^4.0.2"
    }
  }
  
  </code></pre>
  
  <p><strong>test.env file</strong></p>
  
  <pre><code>MONGODB_CONNECTION=mongodb://127.0.0.1:27017/task-manager-api-test-db
  </code></pre>
  
  <p><strong>dev.env file</strong></p>
  
  <pre><code>MONGODB_CONNECTION=mongodb://127.0.0.1:27017/task-manager-api
  </code></pre>
  
  <p><strong>DB Image</strong>
  <a href="https://i.stack.imgur.com/4ZZKl.png" rel="nofollow noreferrer">My current database</a></p>
  
  <p><strong>Issue</strong>
  1. When I am running the above the test suite, jestjs is not creating a new database in the mongodb.
  Please help me out am I doing something wrong.</p>
  
  <p><strong>Test Result in the Terminal when npm run test is ran</strong>
  A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --runInBand --detectOpenHandles to find leaks.
  Test Suites: 1 failed, 1 total
  Tests:       1 failed, 2 passed, 3 total
   FAIL  tests/user.test.js
    × Should signup a new user (187 ms)
    √ Should signin a user (66 ms)
    √ Should not login non existent user (51 ms)</p>
  
  <p>● Should signup a new user</p>
  
  <pre><code>expected 201 "Created", got 400 "Bad Request"
  
    at Test._assertStatus (node_modules/supertest/lib/test.js:268:12)
    at Test._assertFunction (node_modules/supertest/lib/test.js:283:11)
    at Test.assert (node_modules/supertest/lib/test.js:173:18)
    at Server.localAssert (node_modules/supertest/lib/test.js:131:12)
  </code></pre>
  
  <p>Test Suites: 1 failed, 1 total
  Tests:       1 failed, 2 passed, 3 total
  Snapshots:   0 total
  Time:        2.398 s, estimated 3 s
  Ran all test suites related to changed files.</p>