0

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...

  • 1
    I copied your code into an empty directory, installed `should`, `mocha` and `bluebird`, ran your code, and it fails as expected. – Louis Feb 09 '16 at 00:04
  • Hi Louis, I've just repeated my test, in the same way, showing a stack trace, but the mocha result shows '1 passing'. Is the result definitely not '1 passing'? 500 md projects/DELETE_ME/error-demo 501 npm init 502 npm i should bluebird 503 pbpaste >> test.js 504 mocha test.js – andrew oxenburgh Feb 09 '16 at 01:27
  • `0 passing` and on the next line `1 failing`. – Louis Feb 09 '16 at 01:28
  • I did an npm init, npm i should bluebird, npm i, and mocha test.js, with my code in test.js. Is that what you did? – andrew oxenburgh Feb 09 '16 at 01:29
  • No `npm init`. The packages were installed with `npm install should bluebird mocha`. And yes to the rest: `mocha test.js`. – Louis Feb 09 '16 at 01:31
  • Actually, for the test I did both `mocha test.js` and `./node_modules/.bin/mocha test.js`. Same results either way. – Louis Feb 09 '16 at 01:32
  • Thanks Louis. I was using an outdated Mocha (1.16.2, not the latest 2.4.5). You're installing mocha locally tipped me off. – andrew oxenburgh Feb 09 '16 at 01:38

1 Answers1

1

I was using an outdated Mocha...

npm i -g mocha

Did the trick