fix(expect): Playwright matcher options are honored or refused, never silently ignored
Merged
OK
2mo ago+563+563+012345678901234567890123456789-107-107-012345678901234567890123456789
What and why
Audit B36.
- Repro:
e2e runtranspiles without type-checking, so Playwright options reach the runtime. On main,toBeChecked({ checked: false })passes on a checked box, and the same goes fortoBeVisible({ visible: false }),toBeEnabled({ enabled: false }), andtoBeAttached({ attached: false }).not.toContainText('error', { ignoreCase: true })passes onError. Playwright fails all of these. - Cause: every matcher in
packages/e2e/src/expect/async.tsreadoptions?.timeoutand ignored every other key. Theexpect(browser)matchers inpackages/web/src/browser.tsdid the same. - Fix: the options Playwright documents that map cleanly onto e2e are implemented. The four state flags flip their matcher.
ignoreCaseworks ontoHaveText,toContainText,toHaveAccessibleName, andtoHaveAttribute(name, value): a string compares case-folded, and on a RegExp the option adds or stripsi. Every other key, and any flag that is not a boolean, isINVALID_ARGUMENTbefore the first read (existingrejectUnknownOptions). The web matchers andbrowser.waitForURLaccepttimeoutonly.
await expect(checkbox).toBeChecked({ checked: false }); // waits for unchecked
await expect(banner).not.toContainText('error', { ignoreCase: true }); // fails on "Error"
await expect(checkbox).toBeChecked({ indeterminate: true }); // INVALID_ARGUMENT
await expect(browser).toHaveURL('/', { ignoreCase: true }); // INVALID_ARGUMENT
- Tests:
tests/unit/expect-async-options.test.tscovers literal and computed option bags, negated text, RegExp flags, lists, a non-boolean flag, and unknown keys, with a true-condition control for each.tests/integration/matcher-options.test.tsruns the same cases through the CLI against a real browser, options built at runtime; on main all 9 of its tests fail.sdk-types.tspins the new option types. - Docs:
reference/expect.mdx(the interface, the flag semantics, the unknown-option rule),reference/web.mdx(waitForURLtakestimeoutonly),migrate/playwright.mdxrows, andskills/e2e/references/writing-tests.md. e2e/engineexportsrejectUnknownOptions, so the web matchers andwaitForURLuse the runner's check instead of a copy. The peer range stays>=0.15.0 <1: no stable 0.15.0 has shipped, and canaries pin the exact runner.- On top of #570 and #571:
ignoreCasegoes through the list matchers' sharedsatisfies, so thetoContainText([...])subsequence folds case too, and it applies aftertoTextPatternvalidates the pattern.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2eand@e2e-dev/web; the export is additive and mobile does not use it.