【发布时间】:2019-06-15 02:52:33
【问题描述】:
谁能告诉我如何在小部件测试期间实现覆盖颤振错误,以便我可以检查自己的自定义错误。
我在网上看到 sn-ps 提到了这一点,但我所有的实现都失败了
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'
...
我读到您可以执行以下 sn-p 之类的操作,但它没有看到如何/在何处实现它:
final errorHandled = expectAsync0((){});
FlutterError.onError = (errorDetails) {
// handle error
errorHandled();
});
【问题讨论】:
标签: dart flutter flutter-test