【发布时间】:2021-07-07 13:08:08
【问题描述】:
我目前面临一个问题,即在断言查询链中等待 TestCafe ClientFunction 会导致以下代码演示的行为:
const getPageUrl = ClientFunction(() => window.location.href.toString());
// This test works fine
test("Test that works as expected", async t => {
await t
.click(pageElements.someNaviButton) // navigates me to the site with url extension /some/url
.expect(getPageUrl()).contains("/some/url")
});
// This test works fine as well
test("Another test that works as expected", async t => {
await t.click(pageElements.someNaviButton) // navigates me to the site with url extension /some/url
const myPageUrl = await getWindowLocation();
await t.expect(myPageUrl).contains("/some/url")
});
// This test fails
test("Test that does not work as expected", async t => {
await t
.click(pageElements.someNaviButton)
.expect(await getPageUrl()).contains("/some/url")
});
根据TestCafe's documentation,必须等待异步ClientFunctions。这使我感到恼火:我希望第二次测试通过,它确实通过了。在第三个测试的expect方法中等待封装ClientFunction的方法似乎有问题,但这是为什么呢?
可能感兴趣的其他信息:我使用的是 TestCafe 版本 1.14.0。
【问题讨论】:
标签: javascript testing async-await e2e-testing testcafe