user2444238 February 2016

mocha returns a promise, false positive passes, and throws exception indicating error

I'm writing unit tests using Mocha and shouldjs, and bluebird.

According to the documentation (http://shouldjs.github.io/#assertion-finally) I should be able to return a Promise, and get it tested.

It is being run, but not tested. An assertion is thrown, but the test seemingly passes

Here is my code. It's pretty well straight out of the shouldjs docs:

'use strict';

require('should');
var Promise = require('bluebird');

describe('demo should error', function () {
    it('I should fail - but Im not', function () {
        var prm = new Promise(function(resolve, reject) { resolve(10); });
        return prm.should.be.finally.equal(9);
    });
});

When I run this in mocha, I get the following:

    >>> mocha tests/demo.js
    (node) child_process: options.customFds option is deprecated. Use options.stdio instead.

      ․Unhandled rejection AssertionError: expected 10 to be 9
        at Assertion.fail (/Users/andrew/projects/DELETE_ME/2016-02-07/node_modules/should/lib/assertion.js:91:17)
        at Assertion.Object.defineProperty.value (/Users/andrew/projects/DELETE_ME/2016-02-07/node_modules/should/lib/assertion.js:163:19)
    ...

  1 passing (14ms)

So an exception is thrown, but the test seemingly passes.

I also get a false positive when I use native Promise, not bluebird, but the stack trace isn't shown.

Any help gratefully received...

Answers


user2444238 February 2016

I was using an outdated Mocha...

npm i -g mocha

Did the trick

Post Status

Asked in February 2016
Viewed 1,991 times
Voted 14
Answered 1 times

Search




Leave an answer