-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Error is not thrown when running inside Mocha test #266
Comments
You are not returning a promise from the test and you are not calling the |
@petkaantonov Coffeescript automatically adds the var Promise;
Promise = require('bluebird');
describe('test', function() {
return it('should throw an error', function(done) {
return Promise.delay(10).done(function() {
throw new Error("bla");
});
});
}); I've also tested Async errors without calling it('should throw Error', function(done) {
throw new Error('Exit');
});
it('should throw Error inside setTimeout', function(done) {
setTimeout(function() {
throw new Error('Exit');
}, 200);
}); The errors are reproducible without the it('should throw Error inside promise', function() {
return Promise.delay(10).done(function() {
throw new Error('Exit');
});
});
// >> No Error is thrown to Mocha Although it appears to be a problem with Bluebirds it('should throw Error inside promise', function() {
return Promise.delay(10).finally(function() {
throw new Error('Exit');
});
});
// >> Error is thrown |
Also worth noting, there's typically no need for using |
Also promise-returning tests should use () not (done) in the header |
@tgriesser I did not know it('should throw Error', function(done) {
return Promise.delay(10).done(function(text) {
throw new Error(text);
done();
});
});
// >> throws Error |
@thejameskyle Right because you are not using Mocha's promise-based async testing, but instead its done(). The two are incompatible. |
@petkaantonov I don't think Mocha treats this as a synchronous test. If it did, the test wouldn't time out. Mocha only looks at the @thejameskyle That code is equivalent to mine and indeed runs, but I am on a different machine atm. I'll have to retest on mine again tonight. Closing for now until I can reproduce it again. |
Now that I am off my iPad and on something with a real keyboard: this is the best version IMO. it('should throw Error', function() { // NOTE: no done
return Promise.delay(10).then(function(text) { // NOTE: then, not done
throw new Error(text);
});
}); |
Not to be a drag, but although it's different (error created at different time) I'd do: it('should throw Error', function() { // NOTE: no done
return Promise.delay(10).throw(new Error(text));
}); |
Ok, this is a really strange bug and quite likely might belong to Mocha. Given that I likely won't get help there, if anyone has any useful input, I will be grateful.
This test times out. Note that all of the below simply thrown an error:
(this has nothing to do with time, I am just using it for an example). Thanks!
The text was updated successfully, but these errors were encountered: