dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains…
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
$ npx -y skills add flutter/agent-plugins --skill dart-migrate-to-checks-package --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/dart-migrate-to-checks-packageContext preview
The summary Claude sees to decide when to auto-load this skill.
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
name: dart-migrate-to-checks-package description: |- Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents. metadata: model: models/gemini-3.1-pro-preview last_modified: Tue, 09 Jun 2026 19:30:00 GMT
Use this skill when you need to migrate a Dart test suite from the legacy `package:matcher` (which is exported by default from `package:test/test.dart`) to the modern, type-safe, and literate `package:checks` assertion library.
---
"modernize test assertions".
autocomplete in IDEs, and highly detailed failure diagnostics are desired.
---
Follow this structured workflow to safely and systematically migrate a test suite:
dart pub add dev:checks
(it is typically transitively included by `package:test`, which is fine).
to locate all test files containing legacy `expect` or `expectLater` calls.
For any target test file: 1. **Update Imports**:
import 'package:test/scaffolding.dart';
import 'package:checks/checks.dart';in the file, or want to migrate one step at a time, add:
import 'package:test/expect.dart'; // Temporarily allows legacy expect()
2. **Translate Assertions**: Rewrite legacy `expect` and `expectLater` calls to `check` syntax following the [Key Syntax Differences and Pitfalls](#key-syntax-differences-and-pitfalls) and the [Matcher-to-Checks Mapping Table](#matcher-to-checks-mapping-table). 3. **Verify via Compiler**: If migrating fully, remove the `import 'package:test/expect.dart';` line. Any remaining un-migrated `expect` calls will immediately surface as compiler errors, making them easy to find and fix.
dart analyze
Pay close attention to generic type parameters on `.isA<Type>()` and ensure asynchronous expectations are properly awaited (check for `unawaited_futures` warnings).
assertion runtime logic:
dart test
If a test fails, review the extremely detailed failure output of `package:checks` to diagnose if the test is genuinely failing or if the expectation was translated incorrectly.
---
> [!IMPORTANT] > A line-for-line translation can sometimes introduce subtle bugs or false > passes. Always review these key differences carefully:
equals(expected))` performed a **deep equality check** if the arguments were collections (Lists, Maps, Sets).
`operator ==`. Since Dart collections do not override `operator ==` for element-wise comparison, using `.equals` on a collection will check for *identity* and almost certainly fail at runtime.
`.deepEquals(expected)`.
// BEFORE (Matcher) expect(myList, [1, 2, 3]); // AFTER (Checks) check(myList).deepEquals([1, 2, 3]);
argument `reason` to `expect`:
expect(actual, expectation, reason: 'Explanation');
`because` to the `check` function *before* the actual subject:
check(because: 'Explanation', actual).expectation();
a `String` argument into a `RegExp` (e.g., `matches(r'\d')` matched `'1'`).
as a literal string pattern.
pass a `RegExp` object:
// BEFORE (Matcher) expect(someString, matches(r'\d+')); // AFTER (Checks) check(someString).matchesPattern(RegExp(r'\d+'));
`TypeMatcher.having(feature, description, matcher)`:
expect(actual, isA<Person>().having((p) => p.name, 'name', startsWith('A')));available on all `Subject`s, takes one fewer argument, and returns a new `Subject` representing that property. You chain expectations directly
Agent plugins for Flutter, maintained by the Flutter team. A collection of plugins designed to extend AI agent capabilities for Flutter development.
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains…
Entrypoint structure, exit codes, cross-platform scripts. Use when building command line utilities, scripts, or applications.
Collect coverage using the coverage packge and create an LCOV report
Uses get_runtime_errors and lsp to fetch an active stack trace, locate the failing line, apply a fix, and verify resolution via hot_reload.
Define and generate mock objects for external dependencies using `package:mockito` and `build_runner`. Use when unit testing classes that depend on complex…
Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.