-
Notifications
You must be signed in to change notification settings - Fork 112
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
isRejected not behaving as assert.throw #47
Comments
The best way to set this issue to rest once and for all, I think, will be to expose Chai's exception-testing as a Chai util that plugins can use. That is, pulling out the guts of https://github.com/chaijs/chai/blob/master/lib/chai/core/assertions.js#L1029-L1144 into something like /cc @logicalparadox do you agree this would be a valuable addition to Chai? I am not sure on the exact interface yet but the idea would be for plugins to be able to reuse Chai's logic. If you agree I'll try to find time to pull-request up such an extraction from Chai. |
Yes, I like this idea a lot. Overall, the more tools we give plugins the better. |
Hi @domenic, @logicalparadox - I had a go at refactoring out checkError from assertions into its own utility. Its not quite finished (needs some more tests and improved docs on the checkError utility) but I wanted to see if you might take something like this, or if another approach would be better etc. etc. ? |
@vikki you should submit this as a Pull Request to chai's repo, and we can get the ball rolling on implementing this proper 😄. |
I'm rolling up all bugs in the category "isRejected/rejectedWith doesn't behave like Chai's error rejectors" into #166. |
The problem is that expect().to.be.rejected/rejectedWith (and its negation) does not mirror how expect().to.throw (and its negation) behave. Same issue with assert.isRejected in relation to assert.throws.
The problem with issue chaijs#47 is that chai-as-promised somtimes treats the final string parameter as a custom error message. We want to test that it does not do this anymore so we check to make sure that such string is not used as a custom error message.
chai-as-promised's `.rejectedWith` and `assert.isRejected` now mirror how Chai's `.throws` works. Fixes issue chaijs#47.
The problem is that expect().to.be.rejected/rejectedWith (and its negation) does not mirror how expect().to.throw (and its negation) behave. Same issue with assert.isRejected in relation to assert.throws.
The problem with issue #47 is that chai-as-promised somtimes treats the final string parameter as a custom error message. We want to test that it does not do this anymore so we check to make sure that such string is not used as a custom error message.
chai-as-promised's `.rejectedWith` and `assert.isRejected` now mirror how Chai's `.throws` works. Fixes #47.
Hi all! I'm excited about the direction that you're taking chai and chai-as-promised with breaking error checking out into a more modular system. I'm just wondering where the best place to track progress on this would be? I wasn't able to locate the appropriate issue in the chai.js repo. Would this be the best issue to subscribe to? Thanks! |
@JustinLivi The relevant repo is here: https://github.com/chaijs/check-error It'll be included in the upcoming Chai v4 alpha release which will be available via npm. Right now the check-error module only contains helper functions used by Chai's |
@meeber Great! Thanks so much |
assert.throw accepts a string/regex to compare against the thrown error.message
eg:
assert.throw(function() {
throw new Error('error message');
}, 'this is not the error message', 'my msg');
fails with:
AssertionError: expected [Function] to throw error including 'this is not the error message' but got 'error message'
but:
var promise = new Promise(function(resolve, reject) {
reject(new Error('error message'));
});
return assert.isRejected(promise, 'this is not the error message', "optional msg");
does not fail
The text was updated successfully, but these errors were encountered: