fix(expect): waitFor attached and detached, absence under a missing frame, toHaveProperty on primitives, toHaveURL ignoreCase

Merged
OK
2mo ago
+335-51

What and why

Rebuilt on top of #579, which landed the matcher option flags (checked, enabled, visible, attached), ignoreCase on the locator text matchers, and unknown-option refusal. This PR keeps only what #579 does not cover.

  • locator.waitFor read every state except 'visible' as 'hidden', so 'attached', 'detached', and typos passed at once on an absent node. It now supports Playwright's four states and refuses any other state, null included, or an unknown option key with INVALID_ARGUMENT before resolving anything (packages/e2e/src/locator/screen.ts).
  • Absence polls (toBeHidden, toBeVisible({ visible: false }), toBeAttached({ attached: false }), their negations, waitFor detached/hidden) waited for a frame missing from the document until the deadline. They now read it as zero matches: tryRead(..., 'empty') in packages/e2e/src/locator/engine.ts, used by evaluableWithoutNode specs in expect/async.ts.
  • toHaveProperty reads a primitive on the path through its wrapper object, as Jest does, so toHaveProperty('label.length', 3) passes. null/undefined on the path are still absent (packages/e2e/src/expect/values.ts).
  • expect(browser).toHaveURL takes Playwright's ignoreCase. #579 refused it and listed it as missing. urlMatches in e2e/engine gets an optional fourth ignoreCase argument. toHaveTitle still refuses it (Playwright has no such option), and #579's integration test now checks that refusal in place of the toHaveURL one.
  • Docs: screen.mdx (waitFor states), expect.mdx (zero-match forms, absent frames, toHaveURL options, toHaveProperty primitives), engine.mdx (urlMatches), migration rows (waitFor, toHaveURL ignoreCase), skill reference.
await screen.getByTestId('banner').waitFor({ state: 'attached' });
await screen.getByTestId('banner').waitFor({ state: 'atached' }); // INVALID_ARGUMENT
await expect(browser.frameLocator('#absent').getByRole('button')).toBeHidden(); // passes at once
await expect(browser).toHaveURL('/dashboard', { ignoreCase: true });
expect({ label: 'abc' }).toHaveProperty('label.length', 3);

Verified

Ran it locally: yes

  • Scratch project (web page on :6610: hidden node, a banner mounted and a spinner removed after 1200 ms) run through the built CLI against origin/main 84155791 (with #579) and against this branch. The 19 option cases from the original PR plus 3 absent-frame cases. Each asserts what Playwright 1.63 does (pw-oracle.mjs).
  • main now: 8 of 22 fail. This branch: 22 of 22 pass. The 14 that pass on main are #579's cases (state flags, ignoreCase, unknown keys), so they are dropped from this PR.
checkPlaywright 1.63main nowthis branch
waitFor({ state: 'attached' }) on banner mounted at 1200 mswaits ~1.3 s, count 1returns in 18 ms, count 0waits 1.26 s, count 1
waitFor({ state: 'detached' }) on a hidden but attached nodetimes outpasses silentlyLOCATOR_NOT_FOUND
waitFor({ state: 'atached' }) typothrowspasses silentlyINVALID_ARGUMENT
waitFor({ state: 'detached' }) on spinner removed at 1200 mswaits ~1.3 swaits 1.27 s (as hidden)waits 1.28 s
expect(browser).toHaveURL('/dashboard', { ignoreCase }) on /DashboardpassesINVALID_ARGUMENTpasses
toHaveProperty('label.length', 3)passesfailspasses
toBeHidden, toBeAttached({ attached: false }), waitFor({ state: 'detached' }) under frameLocator('#absent')passall three fail after 1 sall pass, 443 ms total
attached after 1264ms, count 1
OK(detached) threw LOCATOR_NOT_FOUND: locator did not become detached: getByTestId("ghost")
OK(atached) threw INVALID_ARGUMENT: waitFor state must be one of attached, detached, visible, hidden, got "atached"
 ✓ |web| tests/frame.e2e.ts (3 tests) 443ms
 ✓ |web| tests/options.e2e.ts (19 tests) 7.91s
      Tests  22 passed (22)
  • pnpm check passes. e2e unit tests: 2345 passed. @e2e-dev/web tests: 441 passed. The touched integration suites (matcher-options, web-class-assertions, web-platform, scripted-polling, scripted-matchers): 48 passed. tests/unit/locator-wait-for.test.ts covers each state with nodes added and removed after 1200 ms, plus the refusals.
  • pnpm test:testbed (70 passed) and pnpm test:web-benchmark (90 passed) pass.

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/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e and @e2e-dev/web. urlMatches gains an optional argument, mobile does not use it.