Skip to main content

prefer-test-matchers

added in: 1.6.0

Warns when the second argument of an expect or expectLater is not a subclass of a Matcher.

Even though matchers might require more code to write, they produce a more readable message when the test fails.

Example

❌ Bad:

void main() {
final array = [1, 2, 3];

expect(array.length, 1); // LINT
expectLater(array.length, 1); // LINT

const value = 'hello';
expect(value is String, isTrue); // LINT
}

✅ Good:

void main() {
final array = [1, 2, 3];

expect(array, hasLength(1));
expectLater(array, hasLength(1));

const value = 'hello';
expect(value, isA<String>());
}