When to use this skill
In a Dart or Flutter project.
When a user asks to migrate to package:checks or just "checks".
How to use this skill
When asked to "migrate to checks", perform the following steps:
- •Analysis:
- •Read through the Dart code in the
test/directory looking for the usage ofexpectfrompackage:test. - •If there are many problems with a given file, go test by test, making sure the tests pass and the analyzer is happy.
- •If you cannot get a given test to pass, leave it as is with a
// TODO: Skipped migrating to package:checks, was too complex.comment explaining why and continue. - •If you are unsure about a conversion, err on the side of leaving the code as is.
- •Make special note of custom matchers. Tell the user to consider migrating these first before continuing.
- •Read through the Dart code in the
- •Dependency Check: Ensure
pubspec.yamlhaspackage:checksindev_dependencies. Add it if missing usingdart pub add --dev checks. - •Import Management: Add
import 'package:checks/checks.dart';to Dart test files. Update thepackage:test/test.dartimport to toimport 'package:test/scaffold.dart. Ensure imports remain sorted. - •Replacement:
- •Replace
expect()andexpectLater()calls withcheck()equivalents. See common patterns below.
- •Verification: The code should analyze cleanly and the tests should pass.
Common Conversion Patterns
- •
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(() => foo(), throwsA<SomeException>());=>check(() => foo()).throws<SomeException>(); - •
expect(a, unorderedEquals(b));=>check(a).isA<Iterable>().unorderedEquals(b); - •
expect(identical(a, b), isTrue);=>check(identical(a, b)).isTrue(); - •
expect(identical(a, b), isFalse);=>check(identical(a, b)).isFalse(); - •
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(a, orderedEquals(b));=>check(a).isA<Iterable>().deepEquals(b); - •
expect(() => foo(), throwsA(isA<ArgumentError>().having((e) => e.message, 'message', 'MSG')));=>check(() => foo()).throws<ArgumentError>().has((e) => e.message as String, (m) => m.contains('MSG'));
Constraints
- •NEVER modify files outside of
pubspec.yamland thetest/directory. - •The code should analyze cleanly and the tests should pass.