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

Assertion does not fail if promise is rejected without reason #56

Closed
tidlund opened this issue May 22, 2014 · 4 comments
Closed

Assertion does not fail if promise is rejected without reason #56

tidlund opened this issue May 22, 2014 · 4 comments
Labels

Comments

@tidlund
Copy link

tidlund commented May 22, 2014

In the following code, the two test cases should fail. However, they pass.

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var assert = chai.assert;
var Q = require('q');

describe('Chai-test', function () {

  it('Should fail if rejected with no value ', function () {
    var promise = Q.reject();
    return assert.becomes(promise,2);
  });

  it('Should fail if rejected with no value (eventually.equal)', function () {
    var promise = Q.reject();
    return assert.eventually.equal(promise,2);
  });
});
@domenic
Copy link
Collaborator

domenic commented May 22, 2014

Darn, I thought I fixed this.

While of course it is a bug in your code if you reject with a non-Error instance, this is indeed something Chai as Promised should catch. I'll try to track this down sometime during the next few weeks, but conferences will be keeping me busy, so pull request appreciated if you'd like it fixed sooner :)

@tidlund
Copy link
Author

tidlund commented May 22, 2014

My mistake, the bug seems to be in Mochas testrunner. This yields the same result (without involvement of chai or chai-as-promised).:

it('Should fail if rejected with no value ', function () {
    return Q.reject();
});

Closing this issue.

@tidlund tidlund closed this as completed May 22, 2014
@domenic
Copy link
Collaborator

domenic commented May 22, 2014

Hmm right, yeah I think it is because Mocha bottoms out at the done style, and

it('should fail if called with an error that is undefined', function (done) {
  done(undefined);
});

counts as a success. In theory they should handle this better for promises.


That said, Chai as Promised should be able to handle this, as Chai as Promised doesn't communicate the original rejection directly to Mocha. Reopening for future fix.

@domenic
Copy link
Collaborator

domenic commented Aug 5, 2016

I'm rolling up all bugs in the category "isRejected/rejectedWith doesn't behave like Chai's error rejectors" into #166.

@domenic domenic closed this as completed Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants