Fill: beforeEach Hook
Fill in the Blank Easy
Question
Fill in the blank to run setup before each test:
Code
let counter;
___(() => {
counter = 0;
});
Hint
The hook name literally means 'before each test'.
Explanation
The correct answer is beforeEach. This hook runs before every individual test in the suite, ensuring a fresh state. Here, it resets counter to 0 before each test, giving each test a clean starting point.
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.