Last active
July 20, 2022 10:55
-
-
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'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have tried that same with flutter 3.0.4, it seems to be working right.