Skip to content

feat: add expect(locator).toBeEmpty() - #1869

Closed
ftaakash wants to merge 9 commits into
e2e-inc:mainfrom
ftaakash:feat/expect-to-be-empty
Closed

ftaakash wants to merge 9 commits into
e2e-inc:mainfrom
ftaakash:feat/expect-to-be-empty

Conversation

@ftaakash

@ftaakash ftaakash commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why

  • Adds the toBeEmpty() locator matcher from the ☂️ Help us bring missing APIs to e2e #1855 checklist (Assertions, expect(locator).toBeEmpty()).
  • Same rule as Playwright: a form control is empty when its value is '' (read raw, so ' ' is not empty; a control the platform reports without a value counts as empty, like toHaveValue('')); any other node is empty when its normalized text is ''.
  • Takes only timeout, works with .not, and is denied on a secure field like the other value/text matchers.
  • Added to the run_code MCP surface, the expect reference, the Playwright and Cypress migration guides (moved out of "What e2e doesn't have yet"), and the skill's matcher list.

Issue

Part of #1855 (Assertions: expect(locator).toBeEmpty()).

Verified

Ran it locally: yes (Windows 11, Node 24.19, pnpm 12.3.4)

  • New tests/unit/expect-async-empty.test.ts fails on main (toBeEmpty is not a function) and passes with the change.
  • pnpm --filter e2e exec vitest run tests/unit/expect-async-empty.test.ts tests/unit/expect-async-options.test.ts tests/unit/expect-async-value.test.ts tests/unit/mcp-code-parse.test.ts tests/integration/scripted-matchers.test.ts: all pass.
  • pnpm --filter e2e test: no new failures compared with main on the same machine (the existing failures on Windows are unrelated: git/\\.\nul, signals, paths).
  • pnpm check passes.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: n/a
  • 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. (No wire change.)
  • Engine contract change (e2e/engine): n/a

View guided diff

A form control is empty when its raw value is '', any other node when its
normalized text is ''. Part of e2e-inc#1855.
@github-actions github-actions Bot added the size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 14 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread skills/e2e/references/writing-tests.md Resolved
Comment thread packages/e2e/src/expect/async.ts Resolved
Comment thread docs/migrate/cypress.mdx Resolved
Comment thread docs/migrate/playwright.mdx Resolved
Comment thread docs/migrate/playwright.mdx Resolved
Comment thread docs/reference/expect.mdx Resolved
…nd migration notes

An option carries a value but is not a field the user fills in, so one with a label and no reported value is not empty. Docs: list toBeEmpty under secure fields and rendered-text reads, and qualify the Cypress be.empty mapping.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 7 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

View guided diff | Re-trigger cubic

…mpty

# Conflicts:
#	docs/migrate/playwright.mdx
#	packages/e2e/tests/integration/scripted-matchers.test.ts
#	packages/e2e/tests/unit/mcp-code-parse.test.ts
#	plugins/e2e/skills/e2e/references/writing-tests.md
#	skills/e2e/references/writing-tests.md

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Reviewed bedb131. Diff is CI-safe, fork CI approved. The matcher shape matches its siblings (readOptions, poll, readsWithheld), but on a real page it passes on elements that visibly show text, so it doesn't behave as Playwright's toBeEmpty as the changeset says.

Must-fix

  1. Value vs text is decided by role (packages/e2e/src/expect/async.ts:565-567, readContent). Playwright decides by tag: INPUT/TEXTAREA are empty when value is empty, anything else when textContent.trim() is empty. A node with a value role and no reported value reads as ''. Built the PR and ran these through the CLI on Chromium; every one passes toBeEmpty() here and fails in Playwright:

    Element this PR Playwright
    <button role="combobox">Select a fruit</button> (Radix Select trigger) empty not empty
    <ul role="listbox"><li role="option">Apple</li></ul> empty not empty
    <div role="textbox">hello</div> empty not empty
    <select><option value="">Choose a colour</option>... empty not empty
    <input type=submit value="Go"> empty not empty
    <input type=checkbox> empty not empty

    The role !== 'option' carve-out patches one case of the wrong discriminator. A plain node.value ?? text breaks mobile, where an empty field's text is its label (packages/mobile/src/nodes.ts:598-604). SemanticNode has no tag, so the node alone can't answer this. Emptiness probably needs to be an engine-side read, like Playwright's elementState. Please hold for a maintainer call on the shape before rewriting (see below).

  2. No real-browser test. Add cases to packages/e2e/tests/integration/web-platform.test.ts, as #1857 did for toHaveRole: ARIA combobox and listbox, native select, contenteditable, whitespace-only value. Those would have caught 1.

Should-fix

  • On mobile, text is the node's own label, so a container with labeled children may read as empty while web reads descendants. Either test it or document it.
  • Drop "as Playwright has it" from the changeset and expect.mdx unless it holds, or list the differences.
  • cubic's two open threads (migrate row { ignoreCase }, Cypress be.empty meaning) are still unresolved.

Maintainer questions: engine-side emptiness read vs a narrower node rule with documented differences; whether a native <select> should copy Playwright (never empty when it has options) or mean "no selected value"; mobile support in scope.

… from Playwright

Add an /empty-matcher fixture page and web-platform cases: empty fields
and blank text, and the six elements from review. The contenteditable
textbox already matches Playwright; the ARIA combobox and listbox, native
select, submit input and checkbox read as empty here, so they are marked
as known differences until emptiness is read engine-side.

Drop 'as Playwright has it' from the changeset, give toBeEmpty its own
row in the Playwright migration table ({ timeout } only), list the
differences there, and note the mobile container case.
@ftaakash

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review and the table. I'm holding the rewrite until you pick the shape. In the meantime, b07a1d6 does the parts that don't depend on it:

  • Real-browser cases in web-platform.test.ts against a new /empty-matcher page: empty input and textarea, a whitespace-only div, a filled input, an input holding spaces, plus the six elements from your table. On Chromium the contenteditable role="textbox" already reads "hello" and is not empty. The other five (ARIA combobox, listbox, native select, submit input, checkbox) read as empty, so they're marked it.fails with a note to drop it once they match.
  • Dropped "as Playwright has it" from the changeset. The Playwright migration page now gives toBeEmpty() its own row ({ timeout } only) and lists those five differences.
  • expect.mdx notes the mobile container case. I haven't checked it on a device.

On your questions, my view:

  1. An engine-side emptiness read, like Playwright's elementState, seems right to me. The node has no tag, so any rule built on roles will keep missing cases. I can do it once you're happy with where it should live.
  2. For a native <select>, I'd copy Playwright (never empty while it has options) so the migration page can say "the same". "No selected value" is already covered by toHaveValue('').
  3. I'd keep mobile out of this PR, document it, and follow up separately if you want it.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread docs/migrate/playwright.mdx Resolved

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked b07a1d6, test-merged onto main fabb0c0. Thanks for holding the rewrite. The new tests and docs are accurate, and the earlier asks that don't depend on the shape decision are done: real-browser cases, changeset wording, the migrate row with { timeout } only, the Cypress be.empty qualifier, and the mobile container note. Must-fix 1 from the last review (value vs text decided by role) is still open and waits on Oskar's call on the shape.

Must fix

  • Translations break after merging main. docs/ja and docs/zh landed on main after this branch's base. On the merge, node scripts/check-docs-translations.ts fails: docs/{ja,zh}/reference/expect.mdx: heading #14 is h3, the English page has h4 and code block #8 differs. Fix: merge main, then add the #### toBeEmpty heading and its code block to both translated reference/expect.mdx pages, in the same position as the English page. Mirroring the new migrate rows in docs/{ja,zh}/migrate/{playwright,cypress}.mdx would be nice, but the check doesn't require it.

Should fix

  • web-platform.test.ts:559 (cubic, real): it.fails.each passes on any throw. If someone renames a case or breaks the fixture, resultByTitle throws "no result titled ...", and that throw counts as the expected failure. I confirmed that all five cases fail today with ASSERTION_FAILED (expect.not.toBeEmpty failed), so the current tests are correct, just easy to break without anyone noticing. Fix: drop it.fails and assert the current behavior directly, expect(result.status).toBe('failed') and expect(result.attempts[0]?.error?.code).toBe('ASSERTION_FAILED'), then flip each case to passed when it matches.
  • The role="textbox" case from the earlier table was swapped for a contenteditable one. <div role="textbox">hello</div> without contenteditable still reads as empty here: I added it to the fixture locally and it fails not.toBeEmpty() with ASSERTION_FAILED. So "the contenteditable textbox already matches" is true, but the non-editable ARIA textbox is a sixth difference. Add it to the known-difference cases and to the list in docs/migrate/playwright.mdx.

Nits

  • docs/migrate/playwright.mdx:363 (cubic, real): "a node with a value role reads its value" should mention that option is the exception and reads its text, as expect.mdx already says.

Verified: vitest run of web-platform, scripted-matchers, expect-async-empty, expect-async-options, and mcp-code-parse gave 172 passed and 5 expected fails. Mutants: dropping normalizeText and dropping the option carve-out each fail a unit test. The integration blank-div case does not catch the first one. CI on b07a1d6 has spec, mobile, docs, docs translations, and benchmark at action_required (fork approval pending), so none of them have run on this head.

The main rewrite still waits on the maintainer's shape call (engine-side read by tag like Playwright vs role-based node rule). The translations fix can land now.

…d docs

Merge main, add toBeEmpty to the ja and zh expect reference pages so the
translation check matches the English outline, replace it.fails with
direct ASSERTION_FAILED checks, cover a non-editable ARIA textbox, and
note that an option reads its text.
@ftaakash

Copy link
Copy Markdown
Contributor Author

Thanks for the re-check. Pushed 76eea00:

  • Merged main and added #### toBeEmpty (text, the two-line example, the table row, the API signature and the secure-fields row) to docs/ja and docs/zh reference/expect.mdx. node scripts/check-docs-translations.ts now reports 162 of 162 pages matching. I left the translated migrate pages as they are.
  • Dropped it.fails. Each known difference now asserts today's result directly (failed with ASSERTION_FAILED), so a renamed case or a broken fixture shows up as a failure. A case moves to the passes list once it matches.
  • Added the non-editable <div role="textbox">hello</div> as a sixth difference, both in the fixture and in the list in docs/migrate/playwright.mdx.
  • The same bullet now says that option reads its text.

The readContent rewrite still waits on the shape decision.

@github-actions github-actions Bot added size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile and removed size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile labels Nov 18, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 5 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked 76eea00 (based on main 847a09e). Every ask from the last review that doesn't depend on the shape decision is done. The main must-fix, deciding value vs text by role instead of by tag like Playwright, is still open and waits on the maintainer's call.

Done

  • Translations: docs/{ja,zh}/reference/expect.mdx have #### toBeEmpty in the right spot. check-docs-translations reports 162 of 162 pages matching.
  • it.fails.each is gone. Each known difference now asserts failed + ASSERTION_FAILED. Mutant: renaming one case title now fails that test, where before it would have counted as an expected failure.
  • The non-editable <div role="textbox">hello</div> is in the fixture, in the difference list, and in docs/migrate/playwright.mdx.
  • The option exception is in the migrate bullet.

Still open (waits on the shape decision)

  • packages/e2e/src/expect/async.ts:577 (readContent): role-based value vs text, from the first review. No change requested until the maintainer picks engine-side read vs node rule.

Nits

  • async.ts:571: the readContent JSDoc still says "as Playwright's does". The changeset and docs dropped that claim, so drop it here too.

Verified

  • vitest run of web-platform, scripted-matchers, expect-async-empty, expect-async-options, mcp-code-parse: 178 passed. oxlint on the changed source and test file is clean. No dashes in added lines.
  • CI on 76eea00: spec, mobile, docs, docs translations, and benchmark are action_required (fork approval pending), so none of them have run on this head. Only check, pr-size, pr-policy, and cubic ran, and all passed.

@ftaakash

Copy link
Copy Markdown
Contributor Author

Dropped "as Playwright's does" from the readContent comment in 5aba6e4. The rest waits on the shape decision.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked 5aba6e4 and test-merged it onto main 8eb3cc2. The merge is clean, so no rebase is needed. The only new commit removes "as Playwright's does" from the readContent comment, which was the nit from the last review. Every ask that doesn't depend on the shape decision is now done.

Still open (waits on the maintainer's shape call)

  • packages/e2e/src/expect/async.ts:577 (readContent) still decides value vs text by role. I re-checked Playwright's matcher in playwright-core's injected script: an INPUT or TEXTAREA is empty when !element.value, and any other element is empty when !element.textContent?.trim(). So the six known differences listed in docs/migrate/playwright.mdx and asserted in web-platform.test.ts still apply. There is nothing to change until the maintainer picks between an engine-side read by tag and the current node rule with documented differences.

Must fix

None that doesn't depend on the shape decision.

Verified

  • On the merge with main: vitest run of expect-async-empty, expect-async-options, mcp-code-parse, scripted-matchers and web-platform gave 179 passed. tsc --noEmit on packages/e2e is clean, and so is oxlint on the changed source and test files. check-docs-translations reports 180 of 180 pages matching. No dashes in added lines.
  • Mutant: dropping the value branch in readContent fails 2 unit tests.
  • Floors: AsyncExpectation is implemented only in e2e, which pins @e2e-dev/core as workspace:*. Web and mobile don't implement it, so no peer floor change is needed.
  • CI on 5aba6e4: only check, cubic, drop and label have run, and all passed. spec, mobile, docs, docs translations and benchmark are action_required (fork approval pending), so the suites haven't run on this head.

@github-actions github-actions Bot added size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile and removed size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile labels Nov 22, 2026

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-checked 7582a16 and test-merged it onto main 5acb822. The merge is clean. The only new commit is a merge of main, and the PR diff is the same as at 5aba6e4. Every ask that doesn't depend on the shape decision is still done.

Still open (waits on the maintainer's shape call)

  • packages/e2e/src/expect/async.ts:577 (readContent) still decides value vs text by role. I checked Playwright's matcher again in playwright-core 1.65.1: an INPUT or TEXTAREA is empty when !element.value, and any other element is empty when !element.textContent?.trim(). So the six differences listed in docs/migrate/playwright.mdx and asserted in web-platform.test.ts still apply.

Must fix

  • None that doesn't depend on the shape decision.

Should fix

  • The cubic thread on docs/migrate/cypress.mdx is still unresolved. You fixed it in 01c3d28 and replied, so please resolve the thread. /ready refuses while a thread is open.

Verified

  • On the merge with main: vitest run of expect-async-empty, expect-async-options, mcp-code-parse, scripted-matchers and web-platform gave 179 passed. tsc --noEmit on packages/e2e is clean, oxlint on the changed files is clean, and the translation check passes. No dashes in added lines.
  • Mutant: dropping the value branch in readContent fails 2 unit tests.
  • Floors: none needed. toBeEmpty lives on AsyncExpectation. Only e2e implements it, and e2e depends on @e2e-dev/core as workspace:*, which publishes as an exact version. Web, mobile and desktop don't implement it, so no peer needs >=0.25.0.
  • CI on 7582a16: everything is green except spec check (and so spec gate). It failed one Playwright parity test, apps/testbed/tests/locator-frame.e2e.ts:78 "should wait for frame to go", which timed out on toBeHidden after an iframe was removed. That test has nothing to do with this PR, which doesn't touch frames or toBeHidden, and spec passed on the last 8 main runs. It looks like a flake, so a re-run should clear it. test x5, ios/android deterministic, web, docs, translations and benchmark all passed.

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Rebase hint at f65722e: main now conflicts after #1998 (run_code runs real JavaScript). That PR deleted packages/e2e/src/session-tools/code-surface.ts and packages/e2e/tests/unit/mcp-code-parse.test.ts, the run_code grammar this PR extended with toBeEmpty. Resolve by accepting the deletion of both files and dropping the toBeEmpty: matcher(0, 1) entry: run_code now calls the real expect, so toBeEmpty works there with no extra wiring. The rest merges cleanly. The earlier hold on the by-tag vs by-role shape still stands, so no new code asks.

KrzysztofMoch pushed a commit that referenced this pull request Nov 24, 2026
Imported from #1869 (head f65722e), squashed onto main. The run_code
grammar entry is dropped: #1998 deleted code-surface.ts, and run_code now
calls the real expect.
okwasniewski pushed a commit that referenced this pull request Nov 24, 2026
* feat(expect): add expect(locator).toBeEmpty()

Imported from #1869 (head f65722e), squashed onto main. The run_code
grammar entry is dropped: #1998 deleted code-surface.ts, and run_code now
calls the real expect.

* fix(expect): read toBeEmpty's emptiness from the engine

toBeEmpty decided value vs text by role in core, since a semantic node
has no tag, so an ARIA combobox or listbox, a non-editable ARIA textbox,
a native select, a submit input, and a checkbox all read as empty where
Playwright finds them not empty.

Engines now report an empty node state on located nodes, never in an
observation and never on a secure field. The web engine reads it in the
page as Playwright does: an input or textarea by its raw value, any other
element by its trimmed text content. The mobile engine reads a text field
by its value and any other node by the text and values in its subtree.
toBeEmpty reads only that state, like toBeEditable reads readonly, and
fails either way where an engine reports none (desktop, older engines).

The empty state stays out of state-matcher failure messages and MCP
locate output.

* docs(expect): leave the secure-field rule to its table in toBeEmpty

* fix(web,mobile): close toBeEmpty's cross-frame and child-field gaps

- Web: read an input or textarea by tag name, as Playwright does. A
  filled input adopted from another frame failed instanceof, fell
  through to its empty text content, and passed toBeEmpty.
- Mobile: a field below a container counts by its value alone and a
  secure one not at all, so a container holding only an empty field with
  a label or hint is empty, and a filled password field is not told.
- Document that iOS reports a field Flutter or Compose Multiplatform
  draws as a plain view, so its placeholder counts.

---------

Co-authored-by: ftaakash <gsaakash@outlook.com>
@kdy1

kdy1 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Note

This text was drafted with AI and posted after human approval.

  • Harness: T3 Code
  • AI agent: Claude Opus 5.5 (claude-opus-5-5)

Thank you for this work, @ftaakash. expect(locator).toBeEmpty() is now on main through #2219, which continued this PR. Your commit is the first commit of #2219. The squash commit c8df611 names you as a co-author.

#2219 also closed the open shape question from the reviews here. On the web, the engine now decides value or text by tag, as Playwright does. An input or a textarea is empty when its value is ''. Any other element is empty when its trimmed textContent is ''.

I am closing this PR because #2219 replaces it. Thanks again for the tests and the docs work.

@kdy1 kdy1 closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants