fix(expect): read a missing frame as zero matches in toHaveCount
Merged
SA
21d ago+101+101+012345678901234567890123456789-55-55-01234567890123456789
What and why
- After an iframe closes,
expect(browser.frameLocator('#checkout').getByRole('button')).toHaveCount(0)polled until the timeout and failedLOCATOR_NOT_FOUND: no frame matches #checkout.not.toHaveCount(2)andtoHaveText([])failed the same way. On the same locator,count()returned 0 andtoBeHidden()passed. - Cause: the whole-set poll samples (
sample()inpackages/e2e/src/expect/async.ts) went throughresolveAllandreadAll, the only reads that still passedmissingFrame: 'wait'.count(),all(),allTextContents(), and the visibility matchers already read a missing frame as zero matches. - Those samples now call
resolveNowandreadAllNowwith the poll's deadline.resolveAllandreadAllduplicated them after the change, so they are gone. - A positive expectation still waits for the frame.
toHaveCount(1)keeps polling and then failsASSERTION_FAILEDwithobserved: count 0, notLOCATOR_NOT_FOUND. The list form oftoHaveTextfails withobserved: text []. - This matters for Cypress users: the migration guide maps
.should('not.exist')to.toHaveCount(0). docs/reference/expect.mdx(Strictness) now lists these matchers among those that read a missing frame as zero matches.
Issue
Fixes #1353
Verified
Ran it locally: yes
- Unit:
tests/unit/expect-missing-frame.test.tsfails on main withLOCATOR_NOT_FOUND(3 of 4 tests) and passes here. - Testbed, real Chromium through the built CLI:
node node_modules/e2e/dist/cli/bin.js run tests/zz-frame-close.e2e.ts --workers 1. The test is an uncommitted scratch file. It serves a cart page withbrowser.routewhose button removes<iframe id="checkout">, taps the button, then runs each assertion onbrowser.frameLocator('#checkout').getByRole('button'). ThetoHaveCount(1)case is expected to fail, and it shows what the failure says.
| main | this branch |
|---|---|
count() is 0: passed | passed |
toBeHidden(): passed | passed |
toHaveCount(0): failed, LOCATOR_NOT_FOUND after 6.4 s | passed |
not.toHaveCount(2): failed, LOCATOR_NOT_FOUND | passed |
toHaveText([]): failed, LOCATOR_NOT_FOUND | passed |
toHaveCount(1): failed, LOCATOR_NOT_FOUND | failed, ASSERTION_FAILED, observed: count 0 |
main:
✓ closed checkout frame > count() is 0 1.44s
✓ closed checkout frame > toBeHidden passes 801ms
× closed checkout frame > toHaveCount(0) passes 6.38s
× closed checkout frame > not.toHaveCount(2) passes 6.01s
× closed checkout frame > toHaveText([]) passes 5.97s
× closed checkout frame > toHaveCount(1) fails on the count 2.02s
LOCATOR_NOT_FOUND: no frame matches #checkout: frameLocator("#checkout") >> getByRole("button")
this branch:
✓ closed checkout frame > count() is 0 503ms
✓ closed checkout frame > toBeHidden passes 354ms
✓ closed checkout frame > toHaveCount(0) passes 313ms
✓ closed checkout frame > not.toHaveCount(2) passes 1.32s
✓ closed checkout frame > toHaveText([]) passes 363ms
× closed checkout frame > toHaveCount(1) fails on the count 1.35s
ASSERTION_FAILED: expect.toHaveCount failed
locator: frameLocator("#checkout") >> getByRole("button")
expected: count 1
observed: count 0 (match count 0)
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 fore2e,@e2e-dev/web, and@e2e-dev/mobile.
🤖 Generated with Claude Code