feat(jest-message-util): Add support for Error cause in test and it - #13935
Conversation
test and it
SimenB
left a comment
There was a problem hiding this comment.
thanks for working on this! can you also add integration tests to failures for errors
- outside of test
- in test
- in hook
?
Also, please add a changelog entry 🙂
Is there already a file with such integration tests for normal error cases or should I create a new test file? |
https://github.com/facebook/jest/blob/main/e2e/__tests__/failures.test.ts |
|
I'll need to fix error with cause tests for node 14. I already had the issue in my first set of tests, I'll update the PR tomorrow with a working versions of the tests for node 14. On a pretty close subject, @SimenB do you think we should add support for error with cause into |
test and ittest and it
That makes sense to me - |
|
Not sure how I should deal with the last error remaining for jest-jasmine. It seems that my last change trying to handle results coming from jasmine and accessing to failure.error somehow changed the behaviour we see in another test 🤔 I'll re-dig a little bit more as I was not expecting such regression and definitely it's linked to my last update attempting to fix part of jasmine runs. |
Making this PR pass first, then I might spend some time on it 👍 |
|
I'm happy to exclude jasmine for now if it proves troublesome |
| const rootErrorOrStack: Error | string = failureDetails | ||
| ? types.isNativeError(failureDetails) || failureDetails instanceof Error | ||
| ? failureDetails // receiving raw errors for jest-circus | ||
| : typeof failureDetails === 'object' && | ||
| 'error' in failureDetails && | ||
| failureDetails.error && | ||
| (types.isNativeError(failureDetails.error) || | ||
| failureDetails.error instanceof Error) | ||
| ? failureDetails.error // receiving instances of FailedAssertion for jest-jasmine | ||
| : content | ||
| : content; |
There was a problem hiding this comment.
this is hard to read - could you extract to a helper function with returns?
|
Ok, I'll drop jasmine support for now then. And retry for it later. |



Summary
For the moment, Jest only supports Error coming with causes if the Error was thrown outside of any test or it. The current PR adds support to test/it cases.
Test plan
Various tests have been added on the PR to show what it will look like on various configurations of Errors coming with causes.