title: Node.js with Express, Jest and SuperTest never fail
body: <p>I'm new in Jest and TDD. Please, help me!
  I'm using supertest to request the API, but even with the server turned off, the tests never fail. I've tried use return or async await and it not solved</p>
  
  <p>I have the following structure at Node.js project:</p>
  
  <pre><code>nodemodules
  src
      controllers
          users-controller.js
      index.js
      routes.js
      server.js
  test
      user.test.js
  package.json
  </code></pre>
  
  <p>package.json:</p>
  
  <pre><code>"scripts": {
      "test": "jest",
      "lint": "eslint src/** test/** --fix",
      "start": "node src/server.js",
      "jest-watch": "jest --watch"
  },
  "devDependencies": {
      "eslint": "^6.8.0",
      "jest": "^25.3.0",
      "supertest": "^4.0.2"
  },
  "dependencies": {
      "body-parser": "^1.19.0",
      "express": "^4.17.1"
  }
  </code></pre>
  
  <p>src/server.js:</p>
  
  <pre><code>const app = require('./index')
  
  app.listen(3001, () =&gt; {
      console.log('Server running on port 3001')
  })
  </code></pre>
  
  <p>src/index.js:</p>
  
  <pre><code>const express = require('express')
  const routes = require('./routes')
  const app = express()
  
  app.use(express.json())
  app.use(routes)
  
  module.exports = app
  </code></pre>
  
  <p>src/routes.js</p>
  
  <pre><code>const routes = require('express').Router()
  const UserController = require('./controllers/users-controller')
  
  routes.get('/', (req, res) =&gt; { res.status(200).send() })
  routes.get('/users', UserController.findAll)
  routes.post('/users', UserController.create)
  
  module.exports = routes
  </code></pre>
  
  <p>src/controllers/user-controller.js</p>
  
  <pre><code>module.exports = {
      findAll(req, res) {
          const users = [
              { name: 'John Doe', mail: 'john@mail.com' }
          ]
          return res.status(200).json(users)
      },
  
      create(req, res) {
          return res.status(201).json(req.body)
      }
  }}
  </code></pre>
  
  <p>test/user.test.js:</p>
  
  <pre><code>const request = require('supertest')
  const app = require('../src/index')
  
  
  test('Should list users', () =&gt; {
      return request(app).get('/users')
          .then(res =&gt; {
              expect(res.status).toBe(200)
              expect(res.body).toHaveLength(1)
              expect(res.body[0]).toHaveProperty('name', 'John Doe')
          })
  })
  
  test('Should insert a user', async () =&gt; {
      await request(app).post('/users')
          .send({ name: 'Walter Mitty', email: 'walter@mail.com' })
          .then(res =&gt; {
              expect(res.status).toBe(201)
              expect(res.body.name).toBe('Walter Mitty')
          })
  })
  </code></pre>
  
  <p>And the result is always the same:</p>
  
  <pre><code>PASS  test / user.test.js
  ✓ Should list users. (16ms)
  ✓ Should insert a user. (13ms)
  
  Test Suites: 1 passed, 1 total
  Tests: 2 passed, 2 total
  Snapshots: 0 total
  Time: 0.456s, estimated 1s
  Ran all test suites related to changed files.
  
  Watch Usage: Press w to show more.
  </code></pre>