ウィジェットのテスト中にオーバーライドするフラッター エラーを実装する方法を誰かに教えてもらえますか?
これについて言及しているスニペットをオンラインで見たことがありますが、実装はすべて失敗します
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 following UnrecognizedTermException was thrown running a test:
Instance of 'UnrecognizedTermException'
...
以下のスニペットのようなことができると読みましたが、それを実装する方法/場所がわかりませんでした:
final errorHandled = expectAsync0((){});
FlutterError.onError = (errorDetails) {
// handle error
errorHandled();
});