Skip to content

Commit f27d810

Browse files
committed
test [nfc]: Mark unawaited future in tests
These are function calls that need to happen asynchronously until we elapse the time with FakeAsync or WidgetTester. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 583582b commit f27d810

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

test/api/fake_api_test.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:checks/checks.dart';
24
import 'package:test/scaffolding.dart';
35
import 'package:zulip/api/exception.dart';
@@ -29,8 +31,8 @@ void main() {
2931
json: {'a': 3});
3032

3133
Map<String, dynamic>? result;
32-
connection.get('aRoute', (json) => json, '/', null)
33-
.then((r) { result = r; });
34+
unawaited(connection.get('aRoute', (json) => json, '/', null)
35+
.then((r) { result = r; }));
3436

3537
async.elapse(const Duration(seconds: 1));
3638
check(result).isNull();
@@ -45,8 +47,8 @@ void main() {
4547
exception: Exception("oops"));
4648

4749
Object? error;
48-
connection.get('aRoute', (json) => null, '/', null)
49-
.catchError((Object e) { error = e; });
50+
unawaited(connection.get('aRoute', (json) => null, '/', null)
51+
.catchError((Object e) { error = e; }));
5052

5153
async.elapse(const Duration(seconds: 1));
5254
check(error).isNull();

test/model/store_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void main() {
295295
connection.prepare(exception: Exception('failed'));
296296
final future = UpdateMachine.load(globalStore, eg.selfAccount.id);
297297
bool complete = false;
298-
future.whenComplete(() => complete = true);
298+
unawaited(future.whenComplete(() => complete = true));
299299
async.flushMicrotasks();
300300
checkLastRequest();
301301
check(complete).isFalse();
@@ -363,7 +363,7 @@ void main() {
363363
connection.prepare(exception: Exception('failed'));
364364
final future = updateMachine.fetchEmojiData(emojiDataUrl);
365365
bool complete = false;
366-
future.whenComplete(() => complete = true);
366+
unawaited(future.whenComplete(() => complete = true));
367367
async.flushMicrotasks();
368368
checkLastRequest();
369369
check(complete).isFalse();

test/widgets/actions_test.dart

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

34
import 'package:checks/checks.dart';
@@ -52,7 +53,7 @@ void main() {
5253
processedCount: 11, updatedCount: 3,
5354
firstProcessedId: null, lastProcessedId: null,
5455
foundOldest: true, foundNewest: true).toJson());
55-
markNarrowAsRead(context, narrow);
56+
unawaited(markNarrowAsRead(context, narrow));
5657
await tester.pump(Duration.zero);
5758
final apiNarrow = narrow.apiEncode()..add(ApiNarrowIs(IsOperand.unread));
5859
check(connection.lastRequest).isA<http.Request>()
@@ -76,7 +77,7 @@ void main() {
7677
processedCount: 11, updatedCount: 3,
7778
firstProcessedId: null, lastProcessedId: null,
7879
foundOldest: true, foundNewest: true).toJson());
79-
markNarrowAsRead(context, narrow);
80+
unawaited(markNarrowAsRead(context, narrow));
8081
await tester.pump(Duration.zero);
8182
check(connection.lastRequest).isA<http.Request>()
8283
..method.equals('POST')
@@ -101,7 +102,7 @@ void main() {
101102
processedCount: 11, updatedCount: 3,
102103
firstProcessedId: null, lastProcessedId: null,
103104
foundOldest: true, foundNewest: true).toJson());
104-
markNarrowAsRead(context, narrow);
105+
unawaited(markNarrowAsRead(context, narrow));
105106
await tester.pump(Duration.zero);
106107
await tester.pumpAndSettle();
107108
check(store.unreads.oldUnreadsMissing).isFalse();
@@ -115,7 +116,7 @@ void main() {
115116

116117
connection.zulipFeatureLevel = 154;
117118
connection.prepare(json: {});
118-
markNarrowAsRead(context, narrow);
119+
unawaited(markNarrowAsRead(context, narrow));
119120
await tester.pump(Duration.zero);
120121
check(connection.lastRequest).isA<http.Request>()
121122
..method.equals('POST')
@@ -133,7 +134,7 @@ void main() {
133134
await prepare(tester);
134135
connection.zulipFeatureLevel = 154;
135136
connection.prepare(json: {});
136-
markNarrowAsRead(context, narrow);
137+
unawaited(markNarrowAsRead(context, narrow));
137138
await tester.pump(Duration.zero);
138139
check(connection.lastRequest).isA<http.Request>()
139140
..method.equals('POST')
@@ -148,7 +149,7 @@ void main() {
148149
await prepare(tester);
149150
connection.zulipFeatureLevel = 154;
150151
connection.prepare(json: {});
151-
markNarrowAsRead(context, narrow);
152+
unawaited(markNarrowAsRead(context, narrow));
152153
await tester.pump(Duration.zero);
153154
check(connection.lastRequest).isA<http.Request>()
154155
..method.equals('POST')
@@ -170,7 +171,7 @@ void main() {
170171
connection.zulipFeatureLevel = 154;
171172
connection.prepare(json:
172173
UpdateMessageFlagsResult(messages: [message.id]).toJson());
173-
markNarrowAsRead(context, narrow);
174+
unawaited(markNarrowAsRead(context, narrow));
174175
await tester.pump(Duration.zero);
175176
check(connection.lastRequest).isA<http.Request>()
176177
..method.equals('POST')
@@ -190,7 +191,7 @@ void main() {
190191
connection.zulipFeatureLevel = 154;
191192
connection.prepare(json:
192193
UpdateMessageFlagsResult(messages: [message.id]).toJson());
193-
markNarrowAsRead(context, narrow);
194+
unawaited(markNarrowAsRead(context, narrow));
194195
await tester.pump(Duration.zero);
195196
check(connection.lastRequest).isA<http.Request>()
196197
..method.equals('POST')

test/widgets/lightbox_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ void main() {
213213
await tester.pumpWidget(const ZulipApp());
214214
await tester.pump();
215215
final navigator = await ZulipApp.navigator;
216-
navigator.push(getImageLightboxRoute(
216+
unawaited(navigator.push(getImageLightboxRoute(
217217
accountId: eg.selfAccount.id,
218218
message: message ?? eg.streamMessage(),
219219
src: src,
220220
thumbnailUrl: thumbnailUrl,
221221
originalHeight: null,
222222
originalWidth: null,
223-
));
223+
)));
224224
await tester.pump(); // per-account store
225225
await tester.pump(const Duration(milliseconds: 301)); // nav transition
226226
}

test/widgets/login_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:checks/checks.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flutter/services.dart';
@@ -90,7 +92,7 @@ void main() {
9092
await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver]));
9193
await tester.pump();
9294
final navigator = await ZulipApp.navigator;
93-
navigator.push(LoginPage.buildRoute(serverSettings: serverSettings));
95+
unawaited(navigator.push(LoginPage.buildRoute(serverSettings: serverSettings)));
9496
await tester.pumpAndSettle();
9597
takeStartingRoutes();
9698
check(pushedRoutes).isEmpty();

0 commit comments

Comments
 (0)