dart-migrate-to-checks-package
Replace the usage of `expect` and similar functions from `package:matcher` to `package:checks` equivalents.
SKILL.mdskills/dart/dart-migrate-to-checks-package/SKILL.md
GitHubContents
Dependency Management
- Add
package:checksas adev_dependencyusingdart pub add dev:checks. - Remove
package:matcherif explicitly listed (often transitively included bypackage:test). - Import
package:checks/checks.dartin all test files undergoing migration.
Syntax Migration Guidelines
- Basic Equality:
expect(actual, equals(expected))→check(actual).equals(expected). - Type Checking:
expect(actual, isA<Type>())→check(actual).isA<Type>(). - Property Extraction:
expect(actual.property, expected)→check(actual).has((a) => a.property, 'property name').equals(expected). - Cascades: Use
..to chain multiple expectations on a single subject. - Async Futures:
await check(someFuture).completes((r) => r.equals(expected)); - Async Streams: Wrap in
StreamQueueor use.withQueue.
Migration Workflow
- Add
package:checksas a dev dependency. - Identify all test files using
package:matcher(expectcalls). - Import
package:checks/checks.dartin target test files. - Rewrite all
expect(...)statements tocheck(...)statements. - Run static analyzer.
- Run tests.
Examples
Basic Assertions:
// Before (matcher):
expect(someList.length, 1);
expect(someString, startsWith('a'));
expect(someObject, isA<Map>());
// After (checks):
check(someList).length.equals(1);
check(someString).startsWith('a');
check(someObject).isA<Map>();
Composed Expectations:
// Before:
expect('foo,bar,baz', allOf([contains('foo'), isNot(startsWith('bar')), endsWith('baz')]));
// After:
check('foo,bar,baz')
..contains('foo')
..not((s) => s.startsWith('bar'))
..endsWith('baz');
Async:
// Before:
expect(Future.value(10), completion(equals(10)));
expect(Future.error('oh no'), throwsA(equals('oh no')));
// After:
await check(Future.value(10)).completes((it) => it.equals(10));
await check(Future.error('oh no')).throws<String>().equals('oh no');