From 1a57929a49fb6fb2db02b47e56c4677ca5ae1704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mac=C3=ADas=20Jim=C3=A9nez?= Date: Thu, 24 Sep 2026 10:35:21 +0200 Subject: [PATCH] docs(browser): fix locators.exact default (#11338) Co-authored-by: Carlos Macias <1439317+cmaciasjimenez@users.noreply.github.com> Co-authored-by: Hiroshi Ogawa <4232207+hi-ogawa@users.noreply.github.com> Co-authored-by: Codex (GPT-5) --- docs/api/browser/locators.md | 18 ++++++------------ packages/browser/context.d.ts | 4 ++-- packages/vitest/src/node/types/browser.ts | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/docs/api/browser/locators.md b/docs/api/browser/locators.md index 357b357da..61a810022 100644 --- a/docs/api/browser/locators.md +++ b/docs/api/browser/locators.md @@ -92,7 +92,7 @@ Providing roles via `role` or `aria-*` attributes to built-in elements that alre - `exact: boolean` - Whether the `name` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `name` is a regular expression. Note that exact match still trims whitespace. + Whether the `name` is matched exactly: case-sensitive and whole-string. Defaults to [`browser.locators.exact`](/config/browser/locators#browser-locators-exact), which is `true` by default. This option is ignored if `name` is a regular expression. Note that exact match still trims whitespace. ```tsx @@ -240,7 +240,7 @@ page.getByAltText('non existing alt text') // ❌ - `exact: boolean` - Whether the `text` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. + Whether the `text` is matched exactly: case-sensitive and whole-string. Defaults to [`browser.locators.exact`](/config/browser/locators#browser-locators-exact), which is `true` by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. **See also** @@ -287,7 +287,7 @@ The `page.getByLabelText('Username')` locator will find every input in the examp - `exact: boolean` - Whether the `text` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. + Whether the `text` is matched exactly: case-sensitive and whole-string. Defaults to [`browser.locators.exact`](/config/browser/locators#browser-locators-exact), which is `true` by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. **See also** @@ -319,7 +319,7 @@ It is generally better to rely on a label using [`getByLabelText`](#getbylabelte - `exact: boolean` - Whether the `text` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. + Whether the `text` is matched exactly: case-sensitive and whole-string. Defaults to [`browser.locators.exact`](/config/browser/locators#browser-locators-exact), which is `true` by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. **See also** @@ -351,7 +351,7 @@ This locator is useful for locating non-interactive elements. If you need to loc - `exact: boolean` - Whether the `text` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. + Whether the `text` is matched exactly: case-sensitive and whole-string. Defaults to [`browser.locators.exact`](/config/browser/locators#browser-locators-exact), which is `true` by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. **See also** @@ -379,7 +379,7 @@ page.getByTitle('Create') // ❌ - `exact: boolean` - Whether the `text` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. + Whether the `text` is matched exactly: case-sensitive and whole-string. Defaults to [`browser.locators.exact`](/config/browser/locators#browser-locators-exact), which is `true` by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. **See also** @@ -404,12 +404,6 @@ page.getByTestId('non-existing-element') // ❌ It is recommended to use this only after the other locators don't work for your use case. Using `data-testid` attributes does not resemble how your software is used and should be avoided if possible. ::: -**Options** - -- `exact: boolean` - - Whether the `text` is matched exactly: case-sensitive and whole-string. Disabled by default. This option is ignored if `text` is a regular expression. Note that exact match still trims whitespace. - **See also** - [testing-library's `ByTestId`](https://testing-library.com/docs/queries/bytestid/) diff --git a/packages/browser/context.d.ts b/packages/browser/context.d.ts index 86a9c3f3b..d9366a247 100644 --- a/packages/browser/context.d.ts +++ b/packages/browser/context.d.ts @@ -427,8 +427,8 @@ export type UserEventWheelOptions = UserEventWheelDeltaOptions | UserEventWheelD export interface LocatorOptions { /** - * Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a - * regular expression. Note that exact match still trims whitespace. + * Whether to find an exact match: case-sensitive and whole-string. Defaults to `browser.locators.exact`, which is + * `true` by default. Ignored when locating by a regular expression. Note that exact match still trims whitespace. */ exact?: boolean } diff --git a/packages/vitest/src/node/types/browser.ts b/packages/vitest/src/node/types/browser.ts index 35847d392..deb45f362 100644 --- a/packages/vitest/src/node/types/browser.ts +++ b/packages/vitest/src/node/types/browser.ts @@ -218,7 +218,7 @@ export interface BrowserConfigOptions { testIdAttribute?: string /** * Should locators match the text exactly by default - * @default false + * @default true */ exact?: boolean /** -- 2.51.2