lecture 15 of 200 completed

Hooks: setup that runs for you

beforeEach, afterEach, beforeAll and afterAll. Choosing between them is a decision about test independence.

What you'll learn

  • What beforeEach, afterEach, beforeAll and afterAll do
  • Why beforeEach protects test independence
  • Why every test gets its own fresh page

You write five tests for the contacts page. Every one begins with the same two lines. Copying them is tedious, and when the flow changes you edit five places.

A hook is code that runs around your tests automatically.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →