jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.23k stars 6.46k forks source link

[Bug]: `expect.assertions` fails when using `test.concurrent` #14263

Open davecardwell opened 1 year ago

davecardwell commented 1 year ago

Version

29.5.0

Steps to reproduce

  1. Clone my repo at https://github.com/davecardwell/jest-concurrent-assertion-repro
  2. npm install
  3. npm test
  4. You should see the error come up

Expected behavior

I expect the test suite to pass.

Actual behavior

The test suite fails with the error:

Expected one assertion to be called but received two assertion calls.

Both tests have expect.assertions(1).

Additional context

Remove the .concurrent or add .skip to either test and the test suite passes.

Environment

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
  Binaries:
    Node: 19.9.0 - ~/nvm/current/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.6.3 - ~/nvm/current/bin/npm
  npmPackages:
    jest: ^29.5.0 => 29.5.0
davecardwell commented 1 year ago

This was previously reported at #12911 but automatically closed as stale. The issue persists in Jest v29.5.0.

mrazauskas commented 1 year ago

@dmitri-gb Could you take a look, please? Perhaps this something what AsyncLocalStorage could help to solve as well? Just thought to ping you, because you are know the concurrent context (;

SimenB commented 1 year ago

Yeah, ASL might be able to solve this as well

PabloPollono-Nexplore commented 1 year ago

do we have an update on this?