Skip to content

Instantly share code, notes, and snippets.

@Muldec
Last active July 20, 2022 10:55
Show Gist options
  • Save Muldec/03a4c8f5dbfc9af475a845bc0a5bdd8f to your computer and use it in GitHub Desktop.
Save Muldec/03a4c8f5dbfc9af475a845bc0a5bdd8f to your computer and use it in GitHub Desktop.
The following assertion was thrown running a test: 'package:flutter_test/src/binding.dart': Failed assertion: line 567 pos 14: '_pendingExceptionDetails != null'
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
Future process;
bool showFutureBuilder = false;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
FlatButton(
child: const Text('WITH FUTURE EXCEPTION'),
onPressed: () {
processButtonWithFuture(futureWithException);
},
),
if (showFutureBuilder)
FutureBuilder(
future: process,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return const Text('WAITING');
if (snapshot.hasError) return const Text('ERROR HAPPENED');
if (snapshot.hasData) return const Text('ALL IS FINE');
},
)
],
);
}
void processButtonWithFuture(Function future) {
setState(() {
showFutureBuilder = true;
process = future();
});
}
Future<String> futureWithException() async {
throw const FormatException();
}
}
void main() {
testWidgets('with Future finds exception', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: MyWidget()));
var handler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails errorDetails) {
if (errorDetails.exception is FormatException)
print('YES');
FlutterError.onError = handler;
};
await tester.tap(find.text('WITH FUTURE EXCEPTION'));
await tester.pump();
await tester.pump();
});
}
@kanakapalli
Copy link

I have tried that same with flutter 3.0.4, it seems to be working right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment