|
| 1 | +import 'dart:async'; |
1 | 2 | import 'dart:convert'; |
2 | 3 | import 'dart:io'; |
3 | 4 |
|
@@ -65,18 +66,16 @@ void main() { |
65 | 66 |
|
66 | 67 | test('send rejects off-realm URL (with default useAuth)', () async { |
67 | 68 | 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))); |
73 | 74 | } |
74 | 75 |
|
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>()); |
80 | 79 | } |
81 | 80 |
|
82 | 81 | // Baseline: normal requests are allowed. |
@@ -246,7 +245,7 @@ void main() { |
246 | 245 | test('API network errors', () async { |
247 | 246 | void checkRequest<T extends Object>( |
248 | 247 | T exception, Condition<NetworkException> condition) { |
249 | | - finish(check(tryRequest(exception: exception)) |
| 248 | + unawaited(check(tryRequest(exception: exception)) |
250 | 249 | .throws<NetworkException>((it) => it |
251 | 250 | ..routeName.equals(kExampleRouteName) |
252 | 251 | ..cause.equals(exception) |
@@ -300,7 +299,7 @@ void main() { |
300 | 299 | void checkMalformed({ |
301 | 300 | int httpStatus = 400, Map<String, dynamic>? json, String? body}) { |
302 | 301 | 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)) |
304 | 303 | .throws<MalformedServerResponseException>((it) => it |
305 | 304 | ..routeName.equals(kExampleRouteName) |
306 | 305 | ..httpStatus.equals(httpStatus) |
|
0 commit comments