Test lifecycle diagram

Ever wondered how beforeEach works in unit test frameworks?

Test lifecycle

Learn about the execution on the new Test lifecycle page.

Why

An experienced developer will find that test hooks work more or less the same in every JavaScript unit test framework. The execution order is also intuitive enough that most people answer correctly when they guess. So why explain it?

You shouldn’t have to guess!

I think it’s worth laying out explicitly, even if this is not unique to QUnit, because a new developer is going to encounter this for the first time.

But more importantly, by demonstrating that the order is stable and guaranteed, I hope this gives you the confidence to lean into it. Build on it! The new Test lifecycle page showcases what’s possible when you depend on this with intent: Nesting hooks, sharing hooks, global hooks, and extending test context.

Thanks

Thanks to FND, Jan D, and NullVoxPopuli for reviewing, improving, and promoting this work!

See also