You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an unexpected exception is thrown inside a test (or beforAll, etc.), print to the console all own enumerable properties of the error, not just the message (and the stacktrace when available).
Motivation
When an operation inside a test (or hook like beforeEach) throws an exception that is not caught or expected, Jest reports the test as failed and print the message of the to the console, but often those errors have properties with useful information to find the culprit. For example Node.js errors usually have a code property, or database drivers can inform the DB error and the query, to name a few; all of this besides the more common stack property.
Since a developer is not expecting the operation to fail (otherwise there would be an expectation for it) it might not be obvious why it is failing or where the error was originated only looking at the message. More often than not I've had to manually catch and print the error to the console to be able to see the properties (or start a debugger). This would be a lot easier and faster if those properties were printed by Jest itself.
Example
I think the idea is pretty clear, but this is what I expect:
test('can go to school and return with homework',()=>{consthomework=goToSchoolWithoutBreakfast();expect(homework.daysWithoutSleep).toBe(2);});
But something unexpected happen... The console then shows:
● can go to school and return with homework
Error: I don't feel so good...
{
causedBy: 'eat to many pizzas',
timeToLive: '3 seconds',
important: 'The key to unlock my safebox and find the <request aborted prematurely>'
}
at pizzaStore:3:14
at Script.runInThisContext (vm.js:120:20)
[...]
at REPLServer.Interface._line (readline.js:658:8)
instead of just:
● can go to school and return with homework
Error: I don't feel so good...
at pizzaStore:3:14
at Script.runInThisContext (vm.js:120:20)
[...]
at REPLServer.Interface._line (readline.js:658:8)
Pitch
I really think this should be the default behaviour of Jest, at least in jest-circus, but I'm not very familiar with custom reporters so maybe I'm wrong.
The text was updated successfully, but these errors were encountered:
Blocked by #9496 for now, as reporters currently don't have access to this info. I do like the idea, though! Not sure where to put that information in the reporter though
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🚀 Feature Proposal
When an unexpected exception is thrown inside a test (or
beforAll
, etc.), print to the console all own enumerable properties of the error, not just the message (and the stacktrace when available).Motivation
When an operation inside a test (or hook like
beforeEach
) throws an exception that is not caught or expected, Jest reports the test as failed and print the message of the to the console, but often those errors have properties with useful information to find the culprit. For example Node.js errors usually have acode
property, or database drivers can inform the DB error and the query, to name a few; all of this besides the more commonstack
property.Since a developer is not expecting the operation to fail (otherwise there would be an expectation for it) it might not be obvious why it is failing or where the error was originated only looking at the message. More often than not I've had to manually catch and print the error to the console to be able to see the properties (or start a debugger). This would be a lot easier and faster if those properties were printed by Jest itself.
Example
I think the idea is pretty clear, but this is what I expect:
But something unexpected happen... The console then shows:
instead of just:
Pitch
I really think this should be the default behaviour of Jest, at least in jest-circus, but I'm not very familiar with custom reporters so maybe I'm wrong.
The text was updated successfully, but these errors were encountered: