From 23d92825a5601dae033f2c5ebacd47989eeaab7e Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 6 Nov 2024 13:46:40 +0100 Subject: [PATCH] chore(fixtures): add rules of thumb for fixture usage --- docs/src/test-fixtures-js.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/src/test-fixtures-js.md b/docs/src/test-fixtures-js.md index 69c080297f..a94ce660a3 100644 --- a/docs/src/test-fixtures-js.md +++ b/docs/src/test-fixtures-js.md @@ -122,6 +122,11 @@ Fixtures have a number of advantages over before/after hooks: - Fixtures are **flexible**. Tests can use any combinations of the fixtures to tailor precise environment they need, without affecting other tests. - Fixtures simplify **grouping**. You no longer need to wrap tests in `describe`s that set up environment, and are free to group your tests by their meaning instead. +Three good signs that something is better as a fixture than as a helper function or before/after hook are: +1. The after hook performs cleanup, or the helper function returns a cleanup helper. +2. There's dependencies between the helper functions, with some helper functions being commonly reused. +3. The before hook or helper function create an object that is "ready to use", similar to the built-in `page` fixture. +
Click to expand the code for the TodoPage