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

Exceptions in test code are missed #244

Open
mkschreder opened this issue Jan 23, 2014 · 7 comments
Open

Exceptions in test code are missed #244

mkschreder opened this issue Jan 23, 2014 · 7 comments

Comments

@mkschreder
Copy link

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.

@caolan
Copy link
Owner

caolan commented Jan 23, 2014

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.

yunong pushed a commit to yunong/nodeunit that referenced this issue Jan 29, 2014
@yunong
Copy link

yunong commented Jan 29, 2014

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.

@yunong
Copy link

yunong commented Jan 29, 2014

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()

@christiaan
Copy link

👍

@arendjr
Copy link

arendjr commented Dec 30, 2014

This looks like a great improvement... why hasn't anything happened with this anymore?

@StuartHa
Copy link

StuartHa commented Mar 4, 2015

👍

@yunong
Copy link

yunong commented Mar 4, 2015

@caolan Can we merge this patch?

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

No branches or pull requests

6 participants