Skip to content

Commit 1aef868

Browse files
committed
api test [nfc]: Simplify some unawaited checks
The `finish` helper is only needed when the future that needs to finish isn't already one created by `check` (which takes care of the effect of `finish` for itself).
1 parent 3c0ed49 commit 1aef868

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

test/api/core_test.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:convert';
23
import 'dart:io';
34

@@ -65,18 +66,16 @@ void main() {
6566

6667
test('send rejects off-realm URL (with default useAuth)', () async {
6768
void checkAllow(String realmUrl, String requestUrl) {
68-
finish(() async {
69-
check(await makeRequest(realmUrl, requestUrl))
70-
.isA<http.Request>()
71-
.url.asString.equals(requestUrl);
72-
}());
69+
// No need to await directly; `check` ensures the future completes
70+
// before the enclosing test is considered complete.
71+
unawaited(check(makeRequest(realmUrl, requestUrl))
72+
.completes((it) => it.isA<http.Request>()
73+
.url.asString.equals(requestUrl)));
7374
}
7475

75-
void checkDeny(String realmUrl, String requestUrl) async {
76-
finish(() async {
77-
await check(makeRequest(realmUrl, requestUrl))
78-
.throws<StateError>();
79-
}());
76+
void checkDeny(String realmUrl, String requestUrl) {
77+
unawaited(check(makeRequest(realmUrl, requestUrl))
78+
.throws<StateError>());
8079
}
8180

8281
// Baseline: normal requests are allowed.
@@ -246,7 +245,7 @@ void main() {
246245
test('API network errors', () async {
247246
void checkRequest<T extends Object>(
248247
T exception, Condition<NetworkException> condition) {
249-
finish(check(tryRequest(exception: exception))
248+
unawaited(check(tryRequest(exception: exception))
250249
.throws<NetworkException>((it) => it
251250
..routeName.equals(kExampleRouteName)
252251
..cause.equals(exception)
@@ -300,7 +299,7 @@ void main() {
300299
void checkMalformed({
301300
int httpStatus = 400, Map<String, dynamic>? json, String? body}) {
302301
assert((json == null) != (body == null));
303-
finish(check(tryRequest(httpStatus: httpStatus, json: json, body: body))
302+
unawaited(check(tryRequest(httpStatus: httpStatus, json: json, body: body))
304303
.throws<MalformedServerResponseException>((it) => it
305304
..routeName.equals(kExampleRouteName)
306305
..httpStatus.equals(httpStatus)

0 commit comments

Comments
 (0)