Question · JavaScript and TypeScript course · Module 11: Testing with Jest

Difference Between beforeAll and beforeEach

What is the difference between beforeAll and beforeEach?

Answer options

  • beforeAll only works with async, beforeEach with synchronous code
  • beforeAll runs once before all tests, beforeEach before each test
  • There is no difference, they are interchangeable
  • beforeAll runs before each test, beforeEach once

You can check the correct answer by solving this task in the CodeWorlds game.