For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt, and this page is available as Markdown at https://rstest.rs/config/test/expect.md.
close
  • English
  • expect

    • Type: ExpectConfig
    • Default: { poll: { interval: 50, timeout: 1000 } } (timeout: 5000 in Browser Mode)

    Configure the defaults used by expect.poll() and the default timeout for Browser Mode expect.element(). Browser Mode uses a 5000ms default poll timeout, while Node Mode uses 1000ms. An implicit default is limited by the remaining current test phase; options passed directly to expect.poll() take precedence and are not capped by this calculation. expect.poll() remains test-only: it can use the active timeout of per-test hooks and fixtures, but it is not available in beforeAll or afterAll.

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      expect: {
        poll: {
          interval: 100,
          timeout: 5000,
        },
      },
    });

    expect.poll

    Global configuration for polling assertions.

    expect.poll.interval

    • Type: number
    • Default: 50

    The interval between expect.poll() retry attempts, in milliseconds. This option does not control the retry interval of Browser Mode expect.element() assertions; the browser provider controls those retries. @rstest/playwright locator/page assertions also retain their fixed 50ms retry interval.

    expect.poll.timeout

    • Type: number
    • Default: 1000 (5000 in Browser Mode)

    The maximum total polling time before the assertion fails, in milliseconds. When omitted at the call site, the configured value is also capped by the remaining current test phase.

    This timeout applies to these APIs:

    APIUses expect.poll.timeout?Per-call override
    expect.poll(fn).toBe(...) in Node or Browser ModeYesexpect.poll(fn, { timeout })
    expect.element(locator).toContainText(...) and other Browser Mode element matchersYestoContainText(text, { timeout })
    Ordinary assertions such as expect(value).toBe(...)No; they do not retry—
    expect(locator).toContainText(...) from @rstest/playwrightYes, since 0.12.0toContainText(text, { timeout })

    An explicit per-call timeout takes precedence over this configuration. For Browser Mode expect.element() and @rstest/playwright locator/page assertions, it is still capped by the remaining active test or hook time when that context is available. For expect.poll(), an explicit timeout is used as provided and can still be ended by the outer test or hook timeout. When no explicit timeout is provided, Rstest uses the smaller of the configured timeout and the remaining active time. For example, a configured 5000ms timeout with only 2000ms remaining does not grant the assertion another five seconds.

    In Browser Mode concurrent tests, use the test-scoped expect fixture to account for that test's remaining time. Shared file-level expect and hooks in describe.concurrent use the configured polling timeout instead. See Browser Mode assertion timeouts.

    When using definePlaywrightConfig, the helper defaults expect.poll.timeout to 5000ms. An explicit expect.poll.timeout overrides that value for both polling and Playwright locator/page assertions. Without the helper, Node Mode defaults to 1000ms.