Why isn't my express test passing? Why isn't my express test passing? express express

Why isn't my express test passing?


Because first argument of the end callback is err, which in your case is undefined and results in

assert.equal(200, undefined.statusCode)

The right way

.end((err, res) => {   if (err) return done(err);   assert.equal(200, res.statusCode);   done();})

Even better would be to use directly .expect(200) as answered by @R. Gulbrandsen.


Try to change your test to use the supertest's expect like this:

import assert from 'assert';import request from 'supertest';import app from '../app';describe('The express App', () => {  it('should return 200', done => {    request(app)      .get('/')      .expect(200)      .end(done);  });});