我是 Flutter 测试的新手,希望你能帮助我。我有一个名为 AddShimmer 的类,看起来像这样 ->
AddShimmer(
child: ListTile(
title: buildLoadingAnimation(context),
),
),
现在,我正在尝试编写一个颤振测试,只是为了检查一个子小部件是否正在传递给 AddShimmer 类。为此,我正在写这样的东西->
testWidgets('Shimmer has a child widget', (WidgetTester tester) async {
const childWidget = ListTile(
title: Text('Loading'),
);
await tester.pumpWidget(
const AddShimmer(child: childWidget)
);
expect(find.byWidget(childWidget), findsOneWidget);
});
当我执行测试时,我得到一个异常,上面写着 ->
The following assertion was thrown building ListTile(dirty):
No Directionality widget found.
ListTile widgets require a Directionality widget ancestor.
The specific widget that could not find a Directionality ancestor was:
ListTile
这是什么意思以及如何测试呢?