我在应用程序中使用InputChips。
InputChip(
key: Key(label.id),
label: Text(label.name),
onDeleted: () => deleteChip(),
),我现在想要创建单元测试来测试delete函数。不幸的是,我没有办法在单元测试中按下芯片的删除图标。有了await tester.tap(find.byKey(Key('1')));,就有可能找到芯片。现在如何定义要单击芯片上的删除图标?
发布于 2020-12-06 20:39:10
您的查找器正在查找和点击InputChip 本身,而不是芯片上的"X“。
您的查找器应该类似于:
find.descendant(
of: find.byKey(Key(label.id)),
matching: find.byIcon(Icons.cancel),
);上面写着“查找InputChip的后代谁是cancel Icon,然后您可以点击它,如果您想:)
当您没有命中目标,或者不确定测试中发生了什么时,请在运行debugDumpApp();后查看控制台
https://stackoverflow.com/questions/65172417
复制相似问题