Skip to content

Commit

Permalink
feat(jest-message-util): improve detection of error causes (#13912)
Browse files Browse the repository at this point in the history
  • Loading branch information
brodo authored Feb 15, 2023
1 parent 9432fc3 commit 267fdbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Features

- `[jest-message-util]` Add support for [error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
- `[jest-message-util]` Add support for [error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) ([#13868](https://github.com/facebook/jest/pull/13868) & [#13912](https://github.com/facebook/jest/pull/13912))

### Fixes

Expand Down
10 changes: 9 additions & 1 deletion packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ export const formatExecError = (
const prefix = '\n\nCause:\n';
if (typeof error.cause === 'string' || typeof error.cause === 'number') {
cause += `${prefix}${error.cause}`;
} else if (types.isNativeError(error.cause)) {
} else if (
types.isNativeError(error.cause) ||
error.cause instanceof Error
) {
/* `isNativeError` is used, because the error might come from another realm.
`instanceof Error` is used because `isNativeError` does return `false` for some
things that are `instanceof Error` like the errors provided in
[verror](https://www.npmjs.com/package/verror) or [axios](https://axios-http.com).
*/
const formatted = formatExecError(
error.cause,
config,
Expand Down

0 comments on commit 267fdbe

Please sign in to comment.