fix(expect): waitFor attached and detached, absence under a missing frame, toHaveProperty on primitives, toHaveURL ignoreCase
Merged
OK
2mo ago+335+335+012345678901234567890123456789-51-51-01234567890123456789
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.waitForread 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,nullincluded, or an unknown option key withINVALID_ARGUMENTbefore resolving anything (packages/e2e/src/locator/screen.ts).- Absence polls (
toBeHidden,toBeVisible({ visible: false }),toBeAttached({ attached: false }), their negations,waitFordetached/hidden) waited for a frame missing from the document until the deadline. They now read it as zero matches:tryRead(..., 'empty')inpackages/e2e/src/locator/engine.ts, used byevaluableWithoutNodespecs inexpect/async.ts. toHavePropertyreads a primitive on the path through its wrapper object, as Jest does, sotoHaveProperty('label.length', 3)passes.null/undefinedon the path are still absent (packages/e2e/src/expect/values.ts).expect(browser).toHaveURLtakes Playwright'signoreCase. #579 refused it and listed it as missing.urlMatchesine2e/enginegets an optional fourthignoreCaseargument.toHaveTitlestill refuses it (Playwright has no such option), and #579's integration test now checks that refusal in place of thetoHaveURLone.- Docs:
screen.mdx(waitFor states),expect.mdx(zero-match forms, absent frames,toHaveURLoptions,toHavePropertyprimitives),engine.mdx(urlMatches), migration rows (waitFor,toHaveURLignoreCase), 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/main84155791 (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.
| check | Playwright 1.63 | main now | this branch |
|---|---|---|---|
waitFor({ state: 'attached' }) on banner mounted at 1200 ms | waits ~1.3 s, count 1 | returns in 18 ms, count 0 | waits 1.26 s, count 1 |
waitFor({ state: 'detached' }) on a hidden but attached node | times out | passes silently | LOCATOR_NOT_FOUND |
waitFor({ state: 'atached' }) typo | throws | passes silently | INVALID_ARGUMENT |
waitFor({ state: 'detached' }) on spinner removed at 1200 ms | waits ~1.3 s | waits 1.27 s (as hidden) | waits 1.28 s |
expect(browser).toHaveURL('/dashboard', { ignoreCase }) on /Dashboard | passes | INVALID_ARGUMENT | passes |
toHaveProperty('label.length', 3) | passes | fails | passes |
toBeHidden, toBeAttached({ attached: false }), waitFor({ state: 'detached' }) under frameLocator('#absent') | pass | all three fail after 1 s | all 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 checkpasses.e2eunit tests: 2345 passed.@e2e-dev/webtests: 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.tscovers each state with nodes added and removed after 1200 ms, plus the refusals.pnpm test:testbed(70 passed) andpnpm 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/**/*.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.urlMatchesgains an optional argument, mobile does not use it.