3

I'm using Mocha and Chai + ChaiHttp for testing my API. The problem I have is that I don't see any error messages when a expect statement is failing.

Here is my code:

it('POST /signup : should create a new user', async () => {
  const user = {
    name: 'Felix',
    email: 'felix@gmail.com',
    password: 'test',
  };

  const res = await chai.request(app).post('/signup').send(user);

  expect(res).to.be.json;
  expect(res).to.have.status(200);
  expect(res.body).to.be.an('object');
  expect(res.body.success).to.equal(true);
  expect(res.body.user).to.have.property('falseAttribute'); // <- test passes with "name"
  expect(res.body.user).to.have.property('token');
});

When it fails because the returned use is expected to have the falseAttribute, it simply shows me the 'it' text highlighted in red:

  Authentication tests
    1) POST /signup : should create a new user`)

In my package.json scripts I put "test": "NODE_ENV=test ./node_modules/.bin/mocha test"

I've already searched the internet for similar problems but I haven't found anything yet. Thank you for your help!

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Felix
  • 166
  • 1
  • 4
  • 20

1 Answers1

0

I figured out the issue. I have a function to catch uncaughtExceptions

process.on('uncaughtException', function (err) {
  logger.fatal(`${(new Date()).toUTCString()}: uncaughtException: '${err.message}'. Stack Trace To Follow.`);
  logger.fatal(err.stack);
  process.exit(1);
});

That thing was killing node. There needs to be a check if you are in test or not, and if you are in test DONT catch the errors.

Samuel Thompson
  • 2,429
  • 4
  • 24
  • 34