expect
- 类型:
ExpectConfig - 默认值:
{ poll: { interval: 50, timeout: 1000 } }(Browser Mode 下timeout为5000)
配置 expect.poll() 使用的默认值,以及 Browser Mode expect.element() 的默认超时时间。Browser Mode 下默认轮询超时为 5000ms,Node Mode 下为 1000ms。隐式使用的默认值会受当前 test 阶段的剩余时间限制;直接传给 expect.poll() 的选项优先级更高,不参与这个限制。expect.poll() 仍然只能在 test 中使用:它可以使用 per-test hook 和 fixture 的 active timeout,但不能在 beforeAll 或 afterAll 中使用。
expect.poll
轮询断言的全局配置。
expect.poll.interval
- 类型:
number - 默认值:
50
expect.poll() 每次重试之间的间隔时间,单位为毫秒。此配置不控制 Browser Mode expect.element() 的重试间隔,后者由浏览器 Provider 控制。@rstest/playwright 的 Locator/Page 断言也保留固定的 50ms 重试间隔。
expect.poll.timeout
- 类型:
number - 默认值:
1000(Browser Mode 下为5000)
断言失败前允许的最长轮询时间,单位为毫秒。调用处未显式传入 timeout 时,实际值还会受当前 test 阶段的剩余时间限制。
此超时时间的作用范围如下:
单次调用显式传入的 timeout 优先于此配置。对于 expect.poll() 和 Browser Mode 的 expect.element(),未显式传入时,如果能获取当前 test 或 hook 的剩余时间,Rstest 会取配置值与剩余时间中较小的值。例如,配置为 5000ms,但当前阶段只剩 2000ms,断言不会再获得完整的五秒。显式传入 timeout 可以跳过这个计算,但不会延长外层的 testTimeout 或 hook timeout。
在 Browser Mode 的并发测试中,使用测试作用域内的 expect fixture,才能按该测试的剩余时间计算。文件级共享 expect 和 describe.concurrent 中的 hook 使用配置的轮询超时。详见浏览器断言超时。
使用 definePlaywrightConfig 时,helper 将 expect.poll.timeout 的默认值设为 5000ms。显式的 expect.poll.timeout 会同时覆盖轮询和 Playwright Locator/Page 断言的超时。不使用 helper 时,Node Mode 默认使用 1000ms。