javascript - 断言超时和等待方法有什么区别

标签 javascript testing timeout assertion testcafe

我有一个测试,我想检查触发请求的次数。我为请求创建了一个记录器,然后在加载 HTML 页面后立即触发 HTTP 请求。因此,t.wait(1000) 测试的问题是绿色的,但是使用 timeout 选项测试不起作用,我不知道为什么。我的错误在哪里?谢谢。

const logger = RequestLogger(/http:\/\/localhost:8080/, {
  logRequestHeaders: true,
  logResponseBody: true,
  stringifyResponseBody: true,
});
test("after first load loading triggers after end scrolling", async t => {
  await t.expect(logger.requests.length).eql(0, '', { timeout: 1000 });
  // await t.wait(1000);
  await t.expect(logger.requests.length).eql(1, '', { timeout: 7000 });
});

最佳答案

根据文档here :

Before TestCafe executes a test action, it waits for XHR and fetch requests to complete within 3 seconds. After TestCafe receives the responses, or the timeout exceeds, the test continues.

If you expect a request to take more time, use a selector or assertion with a custom timeout to wait until the UI reflects the request completion.

这意味着您在第一个 expect 中所做的是将超时从 3 秒缩短到 1 秒,也许这就是它失败的原因。

当您使用 await t.wait(1000) 时,测试将等待 1 秒,然后再继续下一行代码,但默认超时(3 秒)仍然存在。

关于javascript - 断言超时和等待方法有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57504689/

相关文章:

javascript - jquery .更改多个文本框并选择从行到行检索数据

javascript - iOS Safari css 位置在 textarea 聚焦时固定

javascript - 有没有办法生成可以直接用if执行的条件表达式?

reactjs - 使用 Jest 和 Enzyme 调用函数

java - EasyMock 不清楚错误 : "expected: 1, actual: 1"

javascript - 是否有一种纯粹的基于 Promise 的映射/连接集合的方法?

支持 HTTP PATCH 的 REST 测试工具?

c# - 设置 DLL 使用超时

java - Jersey 2.22 : What is the default connect timeout for Client?

android - ANR keyDispatchingTimedOut