Skip to content

Commit 1a57929

Browse files
cmaciasjimenezhi-ogawacodex
authored
docs(browser): fix locators.exact default (#11338)
Co-authored-by: Carlos Macias <[email protected]> Co-authored-by: Hiroshi Ogawa <[email protected]> Co-authored-by: Codex (GPT-5) <[email protected]>
1 parent a0a9396 commit 1a57929

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

‎docs/api/browser/locators.md‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Providing roles via `role` or `aria-*` attributes to built-in elements that alre
9292

9393
- `exact: boolean`
9494

95-
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.
95+
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.
9696

9797
```tsx
9898
<button>Hello World</button>
@@ -240,7 +240,7 @@ page.getByAltText('non existing alt text') // ❌
240240

241241
- `exact: boolean`
242242

243-
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.
243+
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.
244244

245245
**See also**
246246

@@ -287,7 +287,7 @@ The `page.getByLabelText('Username')` locator will find every input in the examp
287287

288288
- `exact: boolean`
289289

290-
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.
290+
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.
291291

292292
**See also**
293293

@@ -319,7 +319,7 @@ It is generally better to rely on a label using [`getByLabelText`](#getbylabelte
319319

320320
- `exact: boolean`
321321

322-
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.
322+
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.
323323

324324
**See also**
325325

@@ -351,7 +351,7 @@ This locator is useful for locating non-interactive elements. If you need to loc
351351

352352
- `exact: boolean`
353353

354-
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.
354+
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.
355355

356356
**See also**
357357

@@ -379,7 +379,7 @@ page.getByTitle('Create') // ❌
379379

380380
- `exact: boolean`
381381

382-
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.
382+
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.
383383

384384
**See also**
385385

@@ -404,12 +404,6 @@ page.getByTestId('non-existing-element') // ❌
404404
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.
405405
:::
406406

407-
**Options**
408-
409-
- `exact: boolean`
410-
411-
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.
412-
413407
**See also**
414408

415409
- [testing-library's `ByTestId`](https://testing-library.com/docs/queries/bytestid/)

‎packages/browser/context.d.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ export type UserEventWheelOptions = UserEventWheelDeltaOptions | UserEventWheelD
427427

428428
export interface LocatorOptions {
429429
/**
430-
* Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a
431-
* regular expression. Note that exact match still trims whitespace.
430+
* Whether to find an exact match: case-sensitive and whole-string. Defaults to `browser.locators.exact`, which is
431+
* `true` by default. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
432432
*/
433433
exact?: boolean
434434
}

‎packages/vitest/src/node/types/browser.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export interface BrowserConfigOptions {
218218
testIdAttribute?: string
219219
/**
220220
* Should locators match the text exactly by default
221-
* @default false
221+
* @default true
222222
*/
223223
exact?: boolean
224224
/**

0 commit comments

Comments
 (0)