diff --git a/CHANGELOG.md b/CHANGELOG.md index cf47e4302d60..a8b4268543cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - `[jest-circus]` Fix snapshot matchers in concurrent tests when nr of tests exceeds `maxConcurrency` ([#14335](https://github.com/jestjs/jest/pull/14335)) +- `[@jest/core]` When running global setup and teardown, do not try to change the `message` property of the thrown error object when the `message` property is unwritable ([#14113](https://github.com/jestjs/jest/pull/14113)) - `[jest-snapshot]` Move `@types/prettier` from `dependencies` to `devDependencies` ([#14328](https://github.com/jestjs/jest/pull/14328)) - `[jest-reporters]` Add "skipped" and "todo" symbols to Github Actions Reporter ([#14309](https://github.com/jestjs/jest/pull/14309)) diff --git a/packages/jest-core/src/runGlobalHook.ts b/packages/jest-core/src/runGlobalHook.ts index 53dced982bc2..4f8a995ca335 100644 --- a/packages/jest-core/src/runGlobalHook.ts +++ b/packages/jest-core/src/runGlobalHook.ts @@ -59,7 +59,14 @@ export default async function runGlobalHook({ }, ); } catch (error) { - if (util.types.isNativeError(error)) { + if ( + util.types.isNativeError(error) && + (Object.getOwnPropertyDescriptor(error, 'message')?.writable || + Object.getOwnPropertyDescriptor( + Object.getPrototypeOf(error), + 'message', + )?.writable) + ) { error.message = `Jest: Got error running ${moduleName} - ${modulePath}, reason: ${error.message}`; throw error;