unit-testing - Flutter 测试:InputChip 点击删除
问题描述
我在我的应用程序中使用InputChips。
InputChip(
key: Key(label.id),
label: Text(label.name),
onDeleted: () => deleteChip(),
),
我现在想创建单元测试来测试删除功能。不幸的是,我发现在单元测试中无法按下芯片的删除图标。有了await tester.tap(find.byKey(Key('1')));
它就可以找到芯片。我现在如何定义我要单击芯片上的删除图标?
解决方案
您的取景器正在寻找并点击它InputChip
本身,而不是芯片上的“X”。
您的取景器应如下所示:
find.descendant(
of: find.byKey(Key(label.id)),
matching: find.byIcon(Icons.cancel),
);
InputChip
这说“找到谁是的后代cancel
Icon
。然后你可以点击它,如果你愿意:)
当您缺少点击目标,或者不确定测试中发生了什么时,请在运行后查看控制台debugDumpApp();
推荐阅读
- java - 如果创建用户时出错,我应该返回什么
- mql4 - MQL 中等效的 ThinkOrSwim 函数
- security - 将上下文相关的编码和/或验证应用于页面上呈现的用户输入是什么?
- solr - 为什么复制字段使用 SOLR _version_ 字段?
- php - 使用 Laravel 在表 mySQL 中动态添加新列
- py2app - py2app捆绑的python仍然指向本地路径
- .htaccess - 如何为 Google Search Console 网站移动工具正确实施 301 重定向?
- mysql - MariaDB/mysql SQL查询问题:我想根据另一列的组值对一列进行部分总和
- git - 删除 git:'credential-manager' 不是 git 命令。来自 Mac
- python - 我尝试使用 ZIP 解压缩 3 个不同的列表。但我得到了价值混合和报价