我有一个测试,我想检查触发请求的次数。我为请求创建了一个记录器,然后在加载 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/