diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e7e2690d1c7..461f20949ee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,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-snapshot]` Move `@types/prettier` from `dependencies` to `devDependencies` ([#14328](https://github.com/jestjs/jest/pull/14328)) ### Chore & Maintenance diff --git a/packages/jest-circus/src/run.ts b/packages/jest-circus/src/run.ts index ea6d5eb3076f..6564b92e8c45 100644 --- a/packages/jest-circus/src/run.ts +++ b/packages/jest-circus/src/run.ts @@ -140,9 +140,8 @@ function startTestsConcurrently(concurrentTests: Array) { jestExpect.setState({currentConcurrentTestName: testNameStorage}); for (const test of concurrentTests) { try { - const promise = testNameStorage.run(getTestID(test), () => - mutex(test.fn), - ); + const testFn = test.fn; + const promise = mutex(() => testNameStorage.run(getTestID(test), testFn)); // Avoid triggering the uncaught promise rejection handler in case the // test fails before being awaited on. // eslint-disable-next-line @typescript-eslint/no-empty-function