npx skills add ...
npx skills add flutter/skills --skill dart-checks-migration
npx skills add flutter/skills --skill dart-checks-migration
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
Use this skill when:
package:matcher to package:checks.grep to identify files using expect or package:matcher.dev_dependencies includes checks.dart pub add --dev checks if missing.import 'package:checks/checks.dart';.import 'package:test/test.dart'; with
import 'package:test/scaffolding.dart'; ONLY after all expect calls
are replaced. This ensures incremental progress.To find candidates for migration, use the following search strategies:
Search for test files that import package:test/test.dart or use expect:
import 'package:test/test.dart';expect\(Search for specific matchers that are easy to migrate:
expect\(.*,\s*equals\(expect\(.*,\s*isNull\)expect\(.*,\s*isTrue\)expect\(.*,\s*isFalse\)expect\(.*,\s*throwsALegacy expect | Modern check |
|---|---|
expect(a, equals(b)) | check(a).equals(b) |
expect(a, isTrue) | check(a).isTrue() |
expect(a, isFalse) | check(a).isFalse() |
expect(a, isNull) | check(a).isNull() |
expect(a, isNotNull) | check(a).isNotNull() |
expect(() => fn(), throwsA<T>()) | check(() => fn()).throws<T>() |
expect(list, hasLength(n)) | check(list).length.equals(n) |
expect(a, closeTo(b, delta)) | check(a).isA<num>().isCloseTo(b, delta) |
expect(a, greaterThan(b)) | check(a).isGreaterThan(b) |
expect(a, lessThan(b)) | check(a).isLessThan(b) |
expect(list, isEmpty) | check(list).isEmpty() |
expect(list, isNotEmpty) | check(list).isNotEmpty() |
expect(list, contains(item)) | check(list).contains(item) |
expect(map, equals(otherMap)) | check(map).deepEquals(otherMap) |
expect(list, equals(otherList)) | check(list).deepEquals(otherList) |
expect(future, completes) | await check(future).completes() |
expect(stream, emitsInOrder(...)) | await check(stream).withQueue.inOrder(...) |
Checking async functions:
check(() => asyncFunc()).throws<T>() causes FALSE POSITIVES because the
closure returns a Future, which is a value, so it "completes normally"
(as a Future).
Correct Usage:
Chaining on void returns:
Many async check methods (like throws) return Future<void>. You cannot
chain directly on them. Use cascades or callbacks.
Wrong:
Correct:
Deep Verification with isA and having:
Legacy:
Modern:
Property Extraction:
Legacy:
Modern:
One-line Cascades:
Since checks often return void, use cascades for multiple assertions on the
same subject.
test/ (and pubspec.yaml).package:checks is stricter about types than matcher.
You may need to add explicit as T casts or isA<T>() checks in the chain.package:matcher that is being migrated
away from.