beforeEach vs beforeAll
Multiple Choice Medium
Question
When does beforeEach run?
Hint
The name tells you — 'before each' test.
Explanation
beforeEach runs before every individual test in the suite, providing a fresh setup for each test. beforeAll runs only once before all tests. Use beforeEach when tests need isolated state (e.g., resetting a database or array), and beforeAll for expensive setup that can be shared safely.
Related Resources
Related Lessons
- Setup and Teardown
Test hooks for setup and cleanup.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.