wishtohear/bucket-water-oms/dart-matcher-best-practices
Claude Code and agent skill by wishtohear/bucket-water-oms
- community
Checking that the SKILL.md file is still in the repository.
Best practices for using `expect` and `package:matcher`. Focuses on readable assertions, proper matcher selection, and avoiding common pitfalls.
Install
npx vskill@latest install wishtohear/bucket-water-oms/dart-matcher-best-practicesSKILL.md
Dart Matcher Best Practices
When to use this skill
Use this skill when:
- Writing assertions using
expectandpackage:matcher. - Migrating legacy manual checks to cleaner matchers.
- Debugging confusing test failures.
Core Matchers
1. Collections (hasLength, contains, isEmpty, unorderedEquals, containsPair)
- `hasLength(n)`:
- Prefer
expect(list, hasLength(n))overexpect(list.length, n). - Gives better error messages on failure (shows actual list content).
- `isEmpty` / `isNotEmpty`:
- Prefer
expect(list, isEmpty)overexpect(list.isEmpty, true). - Prefer
expect(list, isNotEmpty)overexpect(list.isNotEmpty, true).
- `contains(item)`:
- Verify existence without manual iteration.
- Prefer over
expect(list.contains(item), true).
- `unorderedEquals(items)`:
- Verify contents regardless of order.
- Prefer over
expect(list, containsAll(items)).
- `containsPair(key, value)`:
- Verify a map contains a specific key-value pair.
- Prefer over checking
expect(map[key], value)or
expect(map.containsKey(key), true).
2. Type Checks (isA<T> and TypeMatcher<T>)
- `isA<T>()`:
- Prefer for inline assertions:
expect(obj, isA<Type>()). - More concise and readable than
TypeMatcher<Type>(). - Allows chaining constraints using
.having().
- `TypeMatcher<T>`:
- Prefer when defining top-level reusable matchers.
- Use `const`:
const isMyType = TypeMatcher<MyType>(); - Chaining
.having()works here too, but the resulting matcher is notconst.
3. Object Properties (having)
Use .having() on isA<T>() or other TypeMatchers to check properties.
- Descriptive Names: Use meaningful parameter names in the closure (e.g.,
(e) => e.message) instead of generic ones like p0 to improve readability.
This provides detailed failure messages indicating exactly which property failed.
4. Async Assertions
- `completion(matcher)`:
- Wait for a future to complete and check its value.
- Prefer `await expectLater(...)` to ensure the future completes before
the test continues.
await expectLater(future, completion(equals(42))).
- `throwsA(matcher)`:
- Check that a future or function throws an exception.
await expectLater(future, throwsA(isA<StateError>())).expect(() => function(), throwsA(isA<ArgumentError>()))(synchronous
function throwing is fine with expect).
5. Using expectLater
Use await expectLater(...) when testing async behavior to ensure proper sequencing.
Principles
- Readable Failures: Choose matchers that produce clear error messages.
- Avoid Manual Logic: Don't use
ifstatements orforloops for
assertions; let matchers handle it.
- Specific Matchers: Use the most specific matcher available (e.g.,
containsPair for maps instead of checking keys manually).
Related Skills
- [dart-test-fundamentals]: Core
concepts for structuring tests, lifecycles, and configuration.
- [dart-checks-migration]: Use this
skill if you are migrating tests from package:matcher to modern package:checks.
[dart-test-fundamentals]: https://github.com/kevmoo/dash_skills/blob/main/.agent/skills/dart-test-fundamentals/SKILL.md [dart-checks-migration]: https://github.com/kevmoo/dash_skills/blob/main/.agent/skills/dart-checks-migration/SKILL.md
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingbucket-water-oms-admin-mobile/tool/dart_skills_lint/.agents/skills/dart-matcher-best-practices/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wishtohear/bucket-water-oms/dart-matcher-best-practices)