feat(expect)!: pass negated matchers on the first read (ENG-1285)
What
A negated matcher passes on the first read that satisfies the negation, as in Playwright. It used to pass only after the negation had held for 1 s.
await expect(screen.getByRole('dialog')).not.toBeVisible(); // passes on the first read that sees no dialog
await expect(browser).not.toHaveURL('/login');
- Covers
.noton every locator matcher, onexpect(browser)(toHaveURL,toHaveTitle,toHaveClass), ontoHaveScreenshot, andpollCondition({ negated: true })from@e2e-dev/core/engine. - A read whose ref another lookup superseded is no longer read as an absent node by
toBeHidden(),.not.toBeVisible(),.not.toBeAttached(), andwaitFor({ state: 'hidden' | 'detached' }).
Why
Owner decision on 2026-11-13 (ENG-1285): match Playwright. The hold made every passing negated assertion cost 1 s, and it was the last .not row under Planned in the Playwright migration guide.
How it works
The hold lived in one place. Every engine package and matcher polls through pollReads in core; no engine (web, mobile, desktop, or the provider packages) has a window of its own.
pollReadsreturns when a read answers!negated(packages/core/src/internal/time.ts:257). The grace window,NEGATION_GRACE_MS, the "held until the read was cut off" pass, and the rule that a negation takes no read at the deadline are gone. A negated poll now takes its last read at the deadline, as a positive one does. An evaluation that returnsundefinedkeeps both polarities waiting.- The three negated callers get the new behavior with no change of their own: locator matchers (
packages/e2e/src/expect/async.ts:202),expect(browser)(packages/web/src/browser.ts:1039), and.not.toHaveScreenshot(packages/e2e/src/expect/screenshot.ts:204). The other five callers poll withnegated: false. - One thing did rely on the hold.
LocatorEngine.tryReadreturned aNODE_STALEread as zero matches, and the visibility and attachment matchers evaluate zero matches as "absent". Under the hold the next read corrected it; on a first-read pass it would be a false pass.readOnenow reports it as one match with no node andstale: true(packages/core/src/locator/engine.ts:512), the matcher sample carries the flag soconditionEvaluableskips it (packages/e2e/src/expect/async.ts:266), andwaitForsamples again (packages/core/src/locator/screen.ts:718). This also closes the same false pass intoBeHidden()andwaitFor({ state: 'hidden' }), which never had the hold. A failure whose last read was stale saysobserved: a node that went stale before it was readinstead ofhiddenorno node. - #2264 clamped the hold to the timeout after a late wake. With the hold gone, its test and its unreleased changeset (
negated-poll-deadline-clamp.md) are removed. - Docs: the Negation section and the
notdoc comment indocs/reference/expect.mdx,pollConditionindocs/reference/engine.mdx, the migration row moved from Planned to the Assertions mapping indocs/migrate/playwright.mdx, and the skill text inskills/e2eand itsplugins/e2ecopy. The other migrate pages do not mention the hold. Translations are left to lag.
Decisions a reviewer would ask about:
.not.toHaveScreenshotloses the hold too. With it, a frame in the middle of a transition did not pass unless the difference lasted 1 s. Playwright passesnot.toHaveScreenshoton the first capture that differs, and the positive form already matches on the first capture, so one rule for every matcher won over keeping the window for this one. Say so if you want it kept for screenshots.- Two web benchmark tests used the hold as a dwell.
order-historyused.not.toBeHidden()to tell a stuck loader from a slow one; it now expectstoBeHidden({ timeout: 1000 })on the loader to fail, then checks that no order is listed, so it fails when the loader goes away within that second (checked by swapping the loader for an empty state after 400 ms).newsletter-signupread "no feedback rendered" right after the tap; those reads moved after the console-error poll that proves the handler ran. - There is no primitive for "X stays for N ms" any more. The changeset tells users to assert the state that follows. A dwell matcher would be a separate proposal.
- The stability policy asks for a deprecation window before a breaking change. A timing change has no old form to keep alive beside the new one, so this ships as
minorwith**Breaking:**, like the other breaking changes queued for 0.25.0.
Issue
ENG-1285
Verified
Ran it locally: yes
- Testbed, built CLI, real Chromium:
node node_modules/e2e/dist/cli/bin.js run tests/browser.e2e.ts. The new test hides a banner and renames the page for 900 ms after a click, then puts both back, so only a read inside that window sees the negation.
main's pollReads | this PR |
|---|---|
× a negated matcher passes on the first read that sees the negation 5.14s ASSERTION_FAILED: expect.not.toBeVisible failed expected: not visible observed: default states (match count 1) | ✓ a negated matcher passes on the first read that sees the negation 2.40s |
-
Each new test fails with its change reverted: the five negated
pollConditionunit tests, the scripted-engine test of a negation over a state that lasts 900 ms,.not.toHaveScreenshotpassing after one capture (three on main), and the stale-read message test, the four stale-read tests (.not.toBeVisible,.not.toBeAttached,toBeHidden,waitFor), which pass on a node that is still there once thestaleflag is dropped again. -
pnpm check,pnpm test, the testbed suite (619 passed), and the web benchmark suite (95 passed) before the rebase. After the rebase onto8525d2edfaand the review fixes:pnpm check,pnpm test, the testbedtests/browser.e2e.ts(13 passed), and the two changed web benchmark files. -
pnpm bench:ab --suite testbed -- tests/controls.e2e.ts tests/browser.e2e.ts: the suite is 60% faster, all of it inexpect.not.*steps.
bench-ab output
bench-ab: 679519f1 (merge base with origin/main) vs cc2a8e01
apps/testbed: e2e run --workers 1 tests/controls.e2e.ts tests/browser.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x15, Node 24.19.0, load 2.9.
The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.
Behavior
These tests are left out of the timing rows below.
- added tests/browser.e2e.ts › browser fixture › a negated matcher passes on the first read that sees the negation (web)
Timings
Every row but the process wall clock covers the 617 tests whose behavior matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 24.22 s (24.18 s-24.42 s) | 12.50 s (12.48 s-12.53 s) | -48.3% (-49.1% to -48.0%) | faster |
| suite (sum of attempts) | 23.46 s (23.42 s-23.58 s) | 9.38 s (9.35 s-9.40 s) | -60.0% (-60.5% to -59.8%) | faster |
| action (events) | 3.80 s (3.76 s-3.82 s) | 3.77 s (3.75 s-3.80 s) | -0.2% (-2.1% to +0.6%) | same, under the floor |
| step expect.not.toBeFocused | 5.02 s (5.02 s-5.03 s) | 7 ms (6 ms-8 ms) | -99.9% (-99.9% to -99.8%) | faster |
| step expect.not.toBeChecked | 2.01 s (2.01 s-2.01 s) | 3 ms (2 ms-3 ms) | -99.9% (-99.9% to -99.8%) | faster |
| step expect.not.toBeInViewport | 2.01 s (2.01 s-2.01 s) | 20 ms (19 ms-32 ms) | -99.0% (-99.1% to -98.2%) | faster |
| step expect.not.toBeSelected | 2.01 s (2.01 s-2.01 s) | 2 ms (2 ms-3 ms) | -99.9% (-99.9% to -99.9%) | faster |
| step app.open | 1.45 s (1.45 s-1.49 s) | 1.43 s (1.42 s-1.43 s) | -1.8% (-6.7% to -0.4%) | unresolved |
| step expect.toBeEnabled | 1.24 s (1.24 s-1.24 s) | 1.25 s (1.24 s-1.25 s) | +0.4% (-0.1% to +0.7%) | same, under the floor |
| step expect.not.toHaveClass | 1.01 s (1.00 s-1.01 s) | 2 ms (1 ms-2 ms) | -99.8% (-99.9% to -99.8%) | faster |
| step expect.not.toBeExpanded | 1.01 s (1.00 s-1.01 s) | 17 ms (17 ms-17 ms) | -98.3% (-98.4% to -98.3%) | faster |
| step expect.not.toHaveAttribute | 1.00 s (1.00 s-1.00 s) | 1 ms (1 ms-1 ms) | -99.9% (-99.9% to -99.9%) | faster |
| step locator.check | 1.00 s (985 ms-1.02 s) | 982 ms (972 ms-999 ms) | -2.7% (-3.5% to +1.9%) | same |
| step locator.uncheck | 902 ms (900 ms-906 ms) | 915 ms (911 ms-922 ms) | +1.4% (-1.7% to +2.7%) | same |
| step locator.tap | 852 ms (838 ms-883 ms) | 856 ms (846 ms-871 ms) | -0.6% (-2.3% to +4.5%) | same, under the floor |
| step locator.longPress | 753 ms (750 ms-756 ms) | 751 ms (750 ms-753 ms) | -0.3% (-0.9% to +0.5%) | same, under the floor |
| step expect.toBeInViewport | 523 ms (514 ms-523 ms) | 524 ms (513 ms-529 ms) | +0.2% (-3.0% to +4.5%) | same, under the floor |
| step locator.setInputFiles | 355 ms (353 ms-368 ms) | 357 ms (356 ms-369 ms) | +0.7% (-2.4% to +3.5%) | same, under the floor |
| step expect.toHaveText | 335 ms (334 ms-347 ms) | 334 ms (329 ms-338 ms) | -1.8% (-4.8% to +0.3%) | same, under the floor |
| step locator.press | 97 ms (95 ms-100 ms) | 93 ms (90 ms-95 ms) | -5.6% (-12.8% to +1.9%) | same, under the floor |
| step locator.focus | 83 ms (82 ms-84 ms) | 82 ms (82 ms-84 ms) | -0.6% (-9.9% to +1.8%) | same, under the floor |
| step locator.fill | 63 ms (61 ms-65 ms) | 64 ms (63 ms-65 ms) | +0.1% (-7.1% to +6.5%) | same, under the floor |
| step expect.toHaveCount | 57 ms (56 ms-59 ms) | 53 ms (52 ms-54 ms) | -7.0% (-10.1% to -5.4%) | same, under the floor |
| step locator.scrollIntoView | 53 ms (45 ms-62 ms) | 52 ms (36 ms-66 ms) | +14.5% (-44.7% to +57.4%) | same, under the floor |
| step app.restart | 45 ms (44 ms-47 ms) | 45 ms (44 ms-45 ms) | 0.0% (-7.3% to +2.3%) | same |
| step locator.blur | 32 ms (30 ms-33 ms) | 31 ms (31 ms-32 ms) | -1.5% (-15.3% to +5.1%) | same, under the floor |
| step locator.selectOption | 29 ms (29 ms-34 ms) | 24 ms (23 ms-24 ms) | -19.0% (-40.8% to -14.3%) | same, under the floor |
| step locator.secondaryTap | 29 ms (27 ms-52 ms) | 30 ms (29 ms-41 ms) | +3.5% (-29.9% to +36.1%) | same, under the floor |
| step locator.doubleTap | 27 ms (25 ms-29 ms) | 28 ms (27 ms-30 ms) | +5.7% (-5.1% to +19.1%) | same, under the floor |
| step expect.toBeFocused | 27 ms (27 ms-28 ms) | 27 ms (26 ms-29 ms) | -1.9% (-10.4% to +7.9%) | same, under the floor |
| step browser.setNetwork | 25 ms (25 ms-25 ms) | 26 ms (25 ms-27 ms) | +1.9% (0.0% to +14.0%) | same, under the floor |
| step expect.toBeVisible | 22 ms (21 ms-24 ms) | 22 ms (20 ms-22 ms) | -6.6% (-10.8% to +2.4%) | same, under the floor |
| step expect.toBeHidden | 21 ms (20 ms-21 ms) | 18 ms (18 ms-18 ms) | -12.2% (-20.4% to -10.0%) | same, under the floor |
| step expect.toHaveAttribute | 19 ms (19 ms-19 ms) | 19 ms (18 ms-19 ms) | 0.0% (-7.4% to +2.9%) | same |
| step expect.toContainText | 19 ms (18 ms-19 ms) | 19 ms (18 ms-19 ms) | 0.0% (-2.5% to +2.7%) | same |
| step expect.toBeSelected | 18 ms (17 ms-20 ms) | 17 ms (17 ms-18 ms) | -5.6% (-12.5% to +6.1%) | same, under the floor |
| step expect.toBeDisabled | 17 ms (16 ms-18 ms) | 17 ms (16 ms-17 ms) | -5.9% (-15.2% to +9.5%) | same, under the floor |
| step browser.reload | 15 ms (14 ms-17 ms) | 15 ms (14 ms-15 ms) | -3.0% (-17.9% to +7.4%) | same, under the floor |
| step browser.evaluate | 8 ms (8 ms-9 ms) | 8 ms (7 ms-8 ms) | -10.6% (-12.5% to 0.0%) | same, under the floor |
| step expect.toHaveValue | 8 ms (7 ms-8 ms) | 7 ms (7 ms-8 ms) | 0.0% (-26.1% to +8.0%) | same |
| step expect.toHaveClass | 7 ms (6 ms-8 ms) | 4 ms (2 ms-4 ms) | -50.0% (-69.1% to -32.4%) | same, under the floor |
| step browser.goto | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (-10.6% to +29.1%) | same |
| step browser.back | 4 ms (3 ms-4 ms) | 4 ms (3 ms-4 ms) | 0.0% (-22.5% to +15.5%) | same |
| step expect.toBeChecked | 4 ms (3 ms-4 ms) | 4 ms (3 ms-4 ms) | 0.0% (-22.5% to 0.0%) | same |
| step expect.toHaveTitle | 3 ms (2 ms-3 ms) | 2 ms (2 ms-2 ms) | -33.3% (-42.3% to +22.5%) | same, under the floor |
| step browser.forward | 3 ms (3 ms-3 ms) | 3 ms (3 ms-3 ms) | 0.0% (0.0% to 0.0%) | same |
| step expect.toHaveAccessibleName | 2 ms (1 ms-3 ms) | 1 ms (1 ms-1 ms) | -50.0% (-75.0% to 0.0%) | same, under the floor |
| step browser.setViewport | 2 ms (1 ms-2 ms) | 1 ms (1 ms-2 ms) | 0.0% (-50.0% to +100.0%) | same |
| step browser.addInitScript | 1 ms (0 ms-1 ms) | 1 ms (0 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
| step browser.setCookies | 1 ms (0 ms-1 ms) | 1 ms (0 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
| step browser.cookies | 1 ms (0 ms-1 ms) | 1 ms (0 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
| step browser.emulateMedia | 1 ms (1 ms-1 ms) | 1 ms (1 ms-2 ms) | 0.0% (0.0% to +100.0%) | same |
| step expect.toBeAttached | 1 ms (1 ms-1 ms) | 1 ms (1 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
| step expect.toBeExpanded | 1 ms (1 ms-1 ms) | 2 ms (1 ms-2 ms) | 0.0% (0.0% to +100.0%) | same |
| step expect.toHaveURL | 1 ms (0 ms-1 ms) | 1 ms (0 ms-1 ms) | +100.0% (+100.0% to +100.0%) | same, under the floor |
| step browser.title | 0 ms (0 ms-0 ms) | 1 ms (0 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
Counters
| Counter | base | head |
|---|---|---|
| attempts | 29 | 30 |
| events engine | 38 | 40 |
| events poll | 108 | 110 |
| steps | 210 | 218 |
| tests passed | 29 | 30 |
Tests outside the threshold: 9 of 617
| Test | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| tests/controls.e2e.ts › controls › a link reads back its attributes, accessible name, classes, and text (web) | 2.10 s (2.09 s-2.10 s) | 80 ms (78 ms-82 ms) | -96.2% (-96.3% to -96.0%) | faster |
| tests/controls.e2e.ts › controls › blur removes focus from MathML matched by label (web) | 1.10 s (1.09 s-1.10 s) | 84 ms (82 ms-84 ms) | -92.4% (-92.6% to -92.1%) | faster |
| tests/controls.e2e.ts › controls › blur removes focus only from the matched node (web) | 1.11 s (1.11 s-1.12 s) | 104 ms (102 ms-106 ms) | -90.7% (-90.9% to -90.5%) | faster |
| tests/controls.e2e.ts › controls › blur works on an input matched by its current value (web) | 1.13 s (1.12 s-1.13 s) | 112 ms (110 ms-115 ms) | -90.0% (-90.2% to -89.5%) | faster |
| tests/controls.e2e.ts › controls › check and uncheck move checked state, and one radio checks at a time (web) | 2.22 s (2.21 s-2.23 s) | 223 ms (221 ms-239 ms) | -90.0% (-90.1% to -89.1%) | faster |
| tests/controls.e2e.ts › controls › expanded state follows the disclosure toggle (web) | 1.11 s (1.10 s-1.12 s) | 126 ms (116 ms-134 ms) | -88.8% (-89.6% to -87.8%) | faster |
| tests/controls.e2e.ts › controls › focus moves with Tab and Shift+Tab (web) | 2.14 s (2.13 s-2.15 s) | 115 ms (113 ms-117 ms) | -94.6% (-94.8% to -94.4%) | faster |
| tests/controls.e2e.ts › controls › selecting an option moves selected state onto it (web) | 2.12 s (2.11 s-2.13 s) | 103 ms (102 ms-104 ms) | -95.2% (-95.2% to -95.1%) | faster |
| tests/controls.e2e.ts › controls › toBeInViewport follows the scroll position, and no match is outside the viewport (web) | 2.67 s (2.65 s-2.68 s) | 696 ms (657 ms-705 ms) | -73.7% (-76.0% to -72.9%) | faster |
With 617 tests compared at 95%, about 30.9 could land outside by chance.
- Docs screenshots: none. The changed text is three table rows and one short section, and
mint devdoes not build this site locally.
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). Title and changeset: yes. No deprecation window, see "How it works". - 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. No type changed: only the doc comment onAsyncExpectation.not. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.pollConditionkeeps its signature; the changeset covers@e2e-dev/coreande2e.