prefer-test-matchers

Group
Style
Path
lint/style/prefer-test-matchers
Default
Off, opt in
Origin
Falcon
Domain
test
Rule
410 of 512
test

Recommends Matcher expectations and direct type, equality, or ordering matchers.

Invalid

example.dartdart
import 'package:test/test.dart';
void main() {
  test('manual expectations', () async {
    expect(true, true);
    expect(false, false);
    expect(null, null);
    expect(1 == 1, true);
    await expectLater(false, false);
  });
}
Use `isTrue` instead of the literal `true` matcher.
3 test('manual expectations', () async {
4 expect(true, true);
Use `isFalse` instead of the literal `false` matcher.
4 expect(true, true);
5 expect(false, false);
Use `isNull` instead of the literal `null` matcher.
5 expect(false, false);
6 expect(null, null);
Match the actual value directly with `equals`, `isNot`, or an ordering matcher instead of comparing it before `expect`.
6 expect(null, null);
7 expect(1 == 1, true);
Use `isFalse` instead of the literal `false` matcher.
7 expect(1 == 1, true);
8 await expectLater(false, false);

Valid

example.dartdart
import 'package:test/test.dart' as t;
void main() {
  t.test('dedicated matchers', () {
    t.expect(true, t.isTrue);
    t.expect(false, t.isFalse);
    t.expect(null, t.isNull);
    t.expect(1, t.equals(1));
    t.expect([1], t.isNotNull);
    void expect(dynamic actual, dynamic matcher) {}
    expect(true, true);
  });
}

Configure prefer-test-matchers

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-test-matchers": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/prefer-test-matchers: <reason>