Closed InExtremaRes closed 2 years ago
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 is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.
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.