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

Returning the result of .should.be.rejected leads to output on stderr. #97

Closed
insidewhy opened this issue Mar 26, 2015 · 10 comments
Closed

Comments

@insidewhy
Copy link

I would have thought this mocha test would work fine:

  // Either I've made a mistake or chai-as-promised is crap...
  it('finds that chai-as-promised is not broken', function() {
    var Promise = require('bluebird')
    var promise = Promise.reject(Error())
    return promise.should.be.rejected
  })

It looks like it passes but check out the stderr after the test...

  User Model
    ✓ finds that chai-as-promised is not broken 

Unhandled rejection Error
    at Error (native)
    at Context.<anonymous> (/home/mega-totoro/projects/cuddle-friends/server/api/user/user.model.spec.js:40:34)
    at callFn (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runnable.js:223:21)
    at Test.Runnable.run (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runnable.js:216:7)
    at Runner.runTest (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:374:10)
    at /home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:452:12
    at next (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:299:14)
    at /home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:309:7
    at next (/home/mega-totoro/projects/cuddle-friends/node_modules/grunt-mocha-test/node_modules/mocha/lib/runner.js:247:23)

Or am I doing something stupid?

@domenic
Copy link
Collaborator

domenic commented Mar 26, 2015

This is a Bluebird bug/"feature", your tests are fine, but they have strange policies that result in garbage on stderr when promises are being used in ways the author of Bluebird did not anticipate.

@domenic domenic closed this as completed Mar 26, 2015
@insidewhy
Copy link
Author

Thanks for the info.

@adambiggs
Copy link

Any recommendations on how to prevent this with Bluebird?

@insidewhy
Copy link
Author

@adambiggs I gave up on it so I can only recommend "don't use chai-as-promised"

@keithamus
Copy link
Member

That advice could just as easily be "don't use bluebird" 😉

@insidewhy
Copy link
Author

After relying on all that cool stuff like Promise.reduce thenReturn etc. etc. it's too hard to remove it. And doing so just for a tiny test framework is illogical. It's a shame this tool doesn't support the "best" promise library.

@domenic
Copy link
Collaborator

domenic commented Jul 8, 2015

It supports it just fine. Bluebird has some bugs that cause random shit to be spewed onto the console. That's a bug, but not a fatal one (your tests will still pass or fail appropriately), and it's not Chai as Promised's job to fix it.

@insidewhy
Copy link
Author

I'm pretty sceptical of your assertion there, where's the link to the bluebird bug? How come the thousands of projects that use bluebird haven't come across the same thing?

@domenic
Copy link
Collaborator

domenic commented Jul 8, 2015

It's not my responsibility to file a bug on a library I'm not using.

This is a pretty commonly encountered issue with Bluebird; see e.g. http://lmgtfy.com/?q=bluebird+%22Unhandled+rejection%22

Anyway this is pretty clearly turning into something combative and non-productive, and there's no Chai as Promised issue here, so I'm locking this thread.

@chaijs chaijs locked and limited conversation to collaborators Jul 8, 2015
@keithamus
Copy link
Member

Just FYI @ohjames - this isn't Chai As Promised's bug - because the rejected property handles the rejection (right about here), so Bluebird saying this is an unhandled rejection is false. It has been handled, very explicitly.

Also, I've filed petkaantonov/bluebird#695 on your behalf. Hopefully you don't mind - and hopefully this can lead to bluebird fixing the issue on their side.

Lastly I'd also kindly ask you refrain from second guessing the maintainers of open source projects without concrete proof otherwise - not only is it not productive to solving the issue, but the maintainers are very busy, and unless they have masochistic tendencies like I do, cannot spend their time dealing with every comment. I know you can't reply here, but if you feel the need to discuss this further you can reach me on twitter @keithamus.

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

No branches or pull requests

4 participants