Skip to content

feat(expect): support unordered text matching#41804

Open
arnabnandy7 wants to merge 1 commit into
microsoft:mainfrom
arnabnandy7:feature/unordered-to-have-text
Open

feat(expect): support unordered text matching#41804
arnabnandy7 wants to merge 1 commit into
microsoft:mainfrom
arnabnandy7:feature/unordered-to-have-text

Conversation

@arnabnandy7

@arnabnandy7 arnabnandy7 commented Jul 15, 2026

Copy link
Copy Markdown

Adds an ignoreOrder option to expect(locator).toHaveText() for cases where a collection’s contents matter but its DOM order does not.

When enabled, every expected string or regular expression must match exactly one distinct located element, and the collection lengths must remain equal. The implementation uses one-to-one matching instead of sorting, allowing it to correctly handle regular expressions, duplicate values, and overlapping matches such as [/foo/, 'foobar'].

Existing order-sensitive behavior remains unchanged by default. The option also retains Playwright’s web-first retries, text normalization, ignoreCase, useInnerText, and assertion diagnostics.

await expect(page.locator('li')).toHaveText(
  ['Pending', 'Complete'],
  { ignoreOrder: true },
);

Fixes #22275
Fixes #41803

Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support order-insensitive array matching in toHaveText [Feature] ignoreOrder option for toHaveText

1 participant