forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test [nfc]: Introduce "finish" helper for async checks
This brings the file test/api/core_test.dart up to being clean against the `unawaited_futures` lint rule, toward zulip#731. It does so with a smaller diff, and simpler resulting code, than by adding `await` on each of the futures. For comparison: zulip#934 (comment)
- Loading branch information
Showing
2 changed files
with
38 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:test_api/hooks.dart'; | ||
|
||
/// Ensure the test runner will wait for the given future to complete | ||
/// before considering the current test complete. | ||
/// | ||
/// Consider using this function, instead of `await`, when a test invokes | ||
/// a check which is asynchronous and has no interaction with other tasks | ||
/// the test will do later. | ||
/// | ||
/// Use `await`, instead of this function, when it matters what order the | ||
/// rest of the test's logic runs in relative to the asynchronous work | ||
/// represented by the given future. In particular, when calling a function | ||
/// that performs setup for later logic in the test, the returned future | ||
/// should always be awaited. | ||
void finish(Future<void> future) { | ||
final outstandingWork = TestHandle.current.markPending(); | ||
future.whenComplete(outstandingWork.complete); | ||
} |