# Assertion Best Practices

> Use specific assertions (toBeNull, toContain, toHaveLength) over generic ones (toBe, toBeTruthy) Use when writing and organizing tests. Testing category skill.

- Skill: `majiayu000/assertion-best-practices` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/assertion-best-practices`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/assertion-best-practices/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/majiayu000/assertion-best-practices

---


# Assertion Best Practices

Use specific assertions (toBeNull, toContain, toHaveLength) over generic ones (toBe, toBeTruthy). Test one concept per assertion group. Include custom failure messages when the default isn't clear. Avoid asserting implementation details—test observable behavior. Prefer deep equality for objects. Assert negative cases too (doesn't contain, not called).
