Skip to content

Commit f4b6e41

Browse files
committed
msglist test: Ensure later errors get reported in full too
Otherwise, if several different test cases in this file fail due to checks failing inside checkInvariants, then only the first one gets reported in detail with the comparison and the stack trace.
1 parent 1e8f2c2 commit f4b6e41

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/model/message_list_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:convert';
22

33
import 'package:checks/checks.dart';
4+
import 'package:flutter/foundation.dart';
45
import 'package:http/http.dart' as http;
56
import 'package:test/scaffolding.dart';
67
import 'package:zulip/api/backoff.dart';
@@ -27,6 +28,24 @@ const newestResult = eg.newestGetMessagesResult;
2728
const olderResult = eg.olderGetMessagesResult;
2829

2930
void main() {
31+
// Arrange for errors caught within the Flutter framework to be printed
32+
// unconditionally, rather than throttled as they normally are in an app.
33+
//
34+
// When using `testWidgets` from flutter_test, this is done automatically;
35+
// compare the [FlutterError.dumpErrorToConsole] call sites,
36+
// and [FlutterError.onError=] and [debugPrint=] call sites, in flutter_test.
37+
//
38+
// This test file is unusual in needing this manual arrangement; it's needed
39+
// because these aren't widget tests, and yet do have some failures arise as
40+
// exceptions that get caught by the framework: namely, when [checkInvariants]
41+
// throws from within an `addListener` callback. Those exceptions get caught
42+
// by [ChangeNotifier.notifyListeners] and reported there through
43+
// [FlutterError.reportError].
44+
debugPrint = debugPrintSynchronously;
45+
FlutterError.onError = (details) {
46+
FlutterError.dumpErrorToConsole(details, forceReport: true);
47+
};
48+
3049
// These variables are the common state operated on by each test.
3150
// Each test case calls [prepare] to initialize them.
3251
late Subscription subscription;

0 commit comments

Comments
 (0)