Skill: Craft Custom Expectation
"Extract when patterns repeat."
The Standard
- Rule of Three: Extract when the same pattern appears 3+ times.
- Separate File: Put all custom expectations in
tests/Expectations.php. - Return $this: Always return
$thisto enable chaining.
The Anti-Patterns
| Don't | Do | Why |
|---|---|---|
| Extract single-use | Keep inline | Clarity over abstraction |
Forget return $this |
Always return | Chaining breaks |
| Scatter across files | Centralize in Expectations.php |
Discoverability |
| Reinvent built-ins | Use Pest's expectations | Maintenance |
Real-World Examples
See examples.md.