failing before hooks still cause tests to run
Author: Nokel81Created Feb 5, 2021Updated Sep 15, 2026
LabelsNeeds TriageBug Report
Bug Report
A before hook (either set by beforeAll or beforeEach) that fails (either by throwing or by rejecting) does not prevent a test from running.
To Reproduce
- Have a
beforeEachhook always throw - Have a test that always passes (and logs some output)
- Run tests
Expected behaviour
The test fails with "beforeEach hook failed" or something similar.
Link to repl or repo (highly encouraged)
https://repl.it/talk/share/jest-before-hook/119943
envinfo
System:
OS: macOS 10.15.7
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Binaries:
Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.14.8 - ~/repos/lens/node_modules/.bin/npm
npmPackages:
jest: ^26.0.1 => 26.0.1
Though the above repl is configured to be the latest version of jest and it still shows this problem.
Source: jestjs/jest