Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected rejections should not raise 'unhandledRejection' #1134

Closed
erikerikson opened this issue Feb 5, 2018 · 3 comments
Closed

Expected rejections should not raise 'unhandledRejection' #1134

erikerikson opened this issue Feb 5, 2018 · 3 comments

Comments

@erikerikson
Copy link

erikerikson commented Feb 5, 2018

Apologies if this is not the exact right place to raise this...

Reproduction available at https://github.com/erikerikson/chai-bluebird

Using:

OS X, version 10.12.6 (16G1114)
$node --version
v6.11.0
{
    "bluebird": "^3.5.1",
    "chai": "^4.1.2",
    "chai-as-promised": "^7.1.1",
    "mocha": "^5.0.0"
}

Executing:

const BbPromise = require('bluebird');
const chai = require('chai');

chai.use(require('chai-as-promised'))

const expect = chai.expect;

process.on('unhandledRejection', err => {
    console.log(`UNHANDLED! ${err}`);
    throw err;
});

describe('Variables', function variables() {
    it('simpler', () => {
        return expect(BbPromise.reduce([
            BbPromise.resolve('foo'),
            BbPromise.resolve('bar'),
            BbPromise.reject('reason')
        ])).to.be.rejected;
    })
});

Outputs:

chai-bluebird $npm test

> chai-bluebird@1.0.0 test ~/chai-bluebird
> mocha test.spec.js



  Variables
    1) simpler
UNHANDLED! reason
UNHANDLED! TypeError: expecting a function but got [object Undefined]

~/chai-bluebird/node_modules/mocha/lib/runner.js:707
  err.uncaught = true;
               ^

TypeError: Cannot create property 'uncaught' on string 'reason'
    at Runner.uncaught (~/chai-bluebird/node_modules/mocha/lib/runner.js:707:16)
    at process.uncaught (~/chai-bluebird/node_modules/mocha/lib/runner.js:821:10)
    at emitOne (events.js:96:13)
    at process.emit (events.js:188:7)
    at process._fatalException (bootstrap_node.js:296:26)
npm ERR! Test failed.  See above for more details.

@erikerikson
Copy link
Author

erikerikson commented Feb 5, 2018

FWIW, this also behaves similarly if one rejects with an Error instead of with a string:
https://github.com/erikerikson/chai-bluebird/blob/reject-error/test.spec.js#L18

Normally you will observe:

~/chai-bluebird $npm test

> chai-bluebird@1.0.0 test ~/chai-bluebird
> mocha test.spec.js



  Variables
UNHANDLED! Error: reason
    ✓ simpler


  1 passing (12ms)

Note the "UNHANDLED" message indicating that the process emitted an 'unhandledRejection' event.

You may have to run npm test a number of times but if you (with this same code) eventually you will see:

~/chai-bluebird $npm test

> chai-bluebird@1.0.0 test ~/chai-bluebird
> mocha test.spec.js



  Variables
UNHANDLED! Error: reason
    1) simpler
    ✓ simpler


  1 passing (11ms)
  1 failing

  1) Variables
       simpler:
     Uncaught Error: reason
      at Context.it (test.spec.js:19:24)




  1 passing (12ms)
  1 failing

  1) Variables
       simpler:
     Uncaught Error: reason
      at Context.it (test.spec.js:19:24)



npm ERR! Test failed.  See above for more details.

Note the double report and "phantom" test.

@meeber
Copy link
Contributor

meeber commented Feb 6, 2018

@erikerikson I believe this issue is related to petkaantonov/bluebird#1487. I'd recommend letting them know you're running into the same issue with .reduce. (I tested your example with bluebird@3.5.0 and the problem went away).

@erikerikson
Copy link
Author

Thank you @meeber I've narrowed this down further and it does not relate to chai. Have reported to bluebird. Apologies for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants