Can someone show me how to implement overriding flutter errors during widget test so I can check for my own custom errors.
I have seen snippets online mentioning this but all of my implementations fail
void main() {
testWidgets('throws an error when scanning unknown term types', (WidgetTester tester) async {
await tester.pumpWidget(injectTestWidget(new ItemScanScreen()));
await tester.enterText(find.byKey(new Key('term')), '');
await tester.tap(find.byIcon(Icons.send));
await tester.pump();
expect(
tester.takeException(),
isInstanceOf<UnrecognizedTermException>(),
reason: 'should have thrown an UnrecognizedTermException error but didn\'t',
);
});
}
the code above fails with the message below even though it looks like it in fact 'caught' my error:
The following UnrecognizedTermException was thrown running a test:
Instance of 'UnrecognizedTermException'
...
I read that you could do something like the snippet below but it did not see how/where to implement it:
final errorHandled = expectAsync0((){});
FlutterError.onError = (errorDetails) {
// handle error
errorHandled();
});