unit-testing - 测试 dom 库中的 waitFor 未按预期运行
问题描述
我正在使用测试 dom 库来测试 svelte 项目。在这里,当我向输入元素输入“com”时,它会调用端点,并且“COMAN”元素将作为端点的结果发生。所以我输入如下代码。
let inputCom = document.getElementsByTagName("input")[0];
await fireEvent.input(inputCom, { target: { value: "com" } });
await waitFor(() => {
expect(getByText("COMAN"));
});
有时它会等待并且表现良好,但有时它会返回错误。我将回调函数更改为waitFor
asexpect(getByText("COMAN")).toBeVisible()
但我得到了相同的结果。即有时会得到我想要的结果,但有时不会。我认为 waitFor 函数的动作现在不稳定。
解决方案
推荐阅读
- powershell - 打开几个网站和截图 | GDI 错误
- c - 0xC0000005:访问冲突读取位置 0x00000000C284EFA2
- regex - 正则表达式:与小组赛相反
- swift - NSOutlineView 在低于 10.12 的 Mac OS 版本上崩溃,因为默认情况下“stronglyReferencesItems”设置为“false”
- .net - 尽管启用了“仅我的代码”,但 Visual Studio 2019 仍因外部异常而中断
- python - 在 igraphR 和 NetworkX Kamada-Kawai 布局中设置“比例”参数
- android - 在通话期间,是否有一种官方的、受数据保护的方式来显示当前电话应用程序的来电显示信息?
- python - Python For 循环打印语句
- arrays - 如何为我的蛇的数组 x 和 y 设置吸气剂?
- vue.js - 从另一个模块访问状态