TDD testing patterns and best practices. Loads when writing, editing, or debugging test files. Use when creating new tests, fixing failing tests, or improving test coverage.
Order tests to drive design decisions, not just coverage:
Use the Arrange-Act-Assert pattern for every test:
// Arrange — set up test data and dependencies
// Act — call the function under test
// Assert — verify the result
Name tests as: "[function] should [expected behavior] when [condition]" Example: "createUser should return error when email is invalid"
Difficult tests are design feedback, not testing problems:
Don't blindly follow the test pyramid. Ask: "Does this test verify a meaningful responsibility?"