-
Notifications
You must be signed in to change notification settings - Fork 370
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
Exceptions in test code are missed #244
Comments
We already wrap tests in try/catch, if you're using async methods inside the tests then the actual exception may appear elsewhere. Please submit a test case which demonstrates your problem and I'll see if there's anything we can do to improve the reporting. |
Hi, so this actually happens when an exception is thrown asynchronously like so: exports.asyncThrow = function (t) {
setImmediate(function() { throw new Error('thrown asynchronously');});
} Running the following test results in: └─[0] <git:(master✱✈)> ./bin/nodeunit ./test/foo.test.js
foo.test.js
FAILURES: Undone tests (or their setups/teardowns):
- asyncThrow I'll be submitting a patch shortly that will fix this issue. |
Turns out github created a new issue when i submitted my PR, it's under #245 With the patch, functions thrown asynchronously now print their stacks like so: └─[0] <git:(master✱✈)> ./bin/nodeunit ./test/foo.test.js
foo.test.js
Error: thrown asynchronously
at Object._onImmediate (/Users/yunong/workspace/nodeunit/test/foo.test.js:2:37)
at processImmediate [as _immediateCallback] (timers.js:330:15)
FAILURES: Undone tests (or their setups/teardowns):
- asyncThrow
To fix this, make sure all tests call test.done() |
👍 |
This looks like a great improvement... why hasn't anything happened with this anymore? |
👍 |
@caolan Can we merge this patch? |
Exceptions that occur inside test functions are completely missed. This creates issues like test failing but makes it completely unclear where the failure occured. The exceptions should be catched and a stack trace should be printed for any exception that happens inside a test method.
The text was updated successfully, but these errors were encountered: