fix(expect): toContainText list matches an ordered subsequence, like Playwright
Merged
OK
2mo ago+110+110+012345678901234567890123456789-19-19-01234567890123456789
What and why
- Audit B39. Repro: three list items, one reads
Deleted item.not.toContainText(['Deleted item'])passed, andtoContainText(['Alpha', 'Gamma'])failed onAlpha,Beta,Gamma. Playwright does the opposite on both. - Cause: the list form shared
toHaveText's rule, so it needed the match count to equal the list length (packages/e2e/src/expect/async.ts,textListMatcher). A count mismatch made the condition false, and the negation passed on that. - Fix:
toContainText([...])now uses Playwright'sto.contain.text.arrayrule: each entry has to be contained by a distinct match, in list order. It scans greedily and allows extra matches.toHaveText([...])still needs the exact count.
function matchesSubsequence(nodes, patterns, satisfies): boolean {
let next = 0;
for (const node of nodes) {
if (next === patterns.length) break;
if (satisfies(node, patterns[next]!)) next += 1;
}
return next === patterns.length;
}
- Tests: unit tests in
locator-basics.test.tscover a subsequence, negation, ordering, more entries than matches, duplicate entries, and the empty list. Integration tests: one scripted-engine case where negatednot.toContainText(['runner'])fails, plus a real-browser subsequence and an out-of-order negation inweb-platform.test.ts. All of them failed on main. - Docs:
reference/expect.mdx,migrate/playwright.mdx,skills/e2e/references/writing-tests.md, and thetoContainTextJSDoc.
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,@e2edev/web, and@e2edev/mobile.