prefer-expect-later

Path
lint/correctness/prefer-expect-later
Default
Off, opt in
Origin
Falcon
Domain
test
Rule
351 of 512
test

Requires expectLater when a canonical expect call receives an unawaited Future.

Invalid

example.dartdart
import 'package:test/test.dart' as t;
Future<int> number() async => 1;
void main() {
  t.test('unawaited future actuals', () {
    t.expect(Future.value(1), 1);
    t.expect(Future.value(1), t.completes);
    t.expect(Future.error('bad'), t.throwsA(t.equals('bad')));
    t.expect(number(), t.equals(1));
    final pending = Future.value(1);
    t.expect(pending, t.equals(1));
    t.expect(Future.value(1), t.predicate((value) => true));
  });
}
Use `expectLater` and `await` its result when expecting a `Future`.
4 t.test('unawaited future actuals', () {
5 t.expect(Future.value(1), 1);
Use `expectLater` and `await` its result when expecting a `Future`.
5 t.expect(Future.value(1), 1);
6 t.expect(Future.value(1), t.completes);
Use `expectLater` and `await` its result when expecting a `Future`.
6 t.expect(Future.value(1), t.completes);
7 t.expect(Future.error('bad'), t.throwsA(t.equals('bad')));
Use `expectLater` and `await` its result when expecting a `Future`.
7 t.expect(Future.error('bad'), t.throwsA(t.equals('bad')));
8 t.expect(number(), t.equals(1));
Use `expectLater` and `await` its result when expecting a `Future`.
9 final pending = Future.value(1);
10 t.expect(pending, t.equals(1));
Use `expectLater` and `await` its result when expecting a `Future`.
10 t.expect(pending, t.equals(1));
11 t.expect(Future.value(1), t.predicate((value) => true));

Valid

example.dartdart
import 'package:test/test.dart' as t;
void main() {
  t.test('good', () async {
    await t.expectLater(Future.value(1), t.completes);
    await t.expectLater(Stream.value(1), t.emits(1));
    t.expect(1, t.equals(1));
    t.expect(true, t.isTrue);
    t.expect(null, t.isNull);
    final completes = 1;
    t.expect(1, completes);
    void expect(dynamic value, dynamic matcher) {}
    expect(Future.value(1), t.completes);
  });
}

Configure prefer-expect-later

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "prefer-expect-later": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/correctness/prefer-expect-later: <reason>