Jest: test.concurrent ignores beforeEach and afterEach

Created on 26 Feb 2019  ·  7Comments  ·  Source: facebook/jest

🐛 Bug Report

When using test.concurrent with tests, all the scenarios run first and then the beforeEach and afterEach blocks run next.

To Reproduce

Write a simple test suite with a beforeEach , 3 tests using test.concurrent, and afterEach.

Expected behavior

I expect runner to execute beforeEach block, then the test, then afterEach block.

Link to repl or repo (highly encouraged)

test-concurrent bug demo

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

Jest v22.1.2 node v7.4.0 linux/amd64

 PASS  ./concurrent-test.js
  try running parallel by scenario level
    ✓ First Test (3ms)
    ✓ Second Test
    ✓ Third Test (1ms)

  console.log concurrent-test.js:8
    Test 1

  console.log concurrent-test.js:12
    Test 2

  console.log concurrent-test.js:16
    Test 3

  console.log concurrent-test.js:4
    BEFORE

  console.log concurrent-test.js:20
    AFTER

  console.log concurrent-test.js:4
    BEFORE

  console.log concurrent-test.js:20
    AFTER

  console.log concurrent-test.js:4
    BEFORE

  console.log concurrent-test.js:20
    AFTER

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        0.993s, estimated 1s
Ran all test suites.

Bug Concurrent

All 7 comments

https://github.com/facebook/jest/issues/4281 dupliacted issue
it would be very nice if jest fix it

@SimenB It seems easy to change the workflow in jest-circus to fix this, I've made a POC. Let me know if this approach would be a good solution

But not sure if Before and After make sense for test.concurrent, if I perform a stateful operation in the hooks then the tests will be indeterministic

@Mark1626 beforeEach and afterEach might not make a ton of sense for test.concurrent, but beforeAll and afterAll would I think.

@SimenB bump

Please fix.

Was this page helpful?
0 / 5 - 0 ratings