@vitest/browser 3.1.0-beta.2 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/jest-dom.d.ts CHANGED
@@ -2,718 +2,629 @@
2
2
 
3
3
  import { ARIARole } from './aria-role.ts'
4
4
 
5
- declare namespace matchers {
6
- interface TestingLibraryMatchers<E, R> {
7
- /**
8
- * @deprecated
9
- * since v1.9.0
10
- * @description
11
- * Assert whether a value is a DOM element, or not. Contrary to what its name implies, this matcher only checks
12
- * that you passed to it a valid DOM element.
13
- *
14
- * It does not have a clear definition of what "the DOM" is. Therefore, it does not check whether that element
15
- * is contained anywhere.
16
- * @see
17
- * [testing-library/jest-dom#toBeInTheDom](https://github.com/testing-library/jest-dom#toBeInTheDom)
18
- */
19
- toBeInTheDOM(container?: HTMLElement | SVGElement): R
20
- /**
21
- * @description
22
- * Assert whether an element is present in the document or not.
23
- * @example
24
- * <svg data-testid="svg-element"></svg>
25
- *
26
- * expect(queryByTestId('svg-element')).toBeInTheDocument()
27
- * expect(queryByTestId('does-not-exist')).not.toBeInTheDocument()
28
- * @see
29
- * [testing-library/jest-dom#tobeinthedocument](https://github.com/testing-library/jest-dom#tobeinthedocument)
30
- */
31
- toBeInTheDocument(): R
32
- /**
33
- * @description
34
- * This allows you to check if an element is currently visible to the user.
35
- *
36
- * An element is visible if **all** the following conditions are met:
37
- * * it does not have its css property display set to none
38
- * * it does not have its css property visibility set to either hidden or collapse
39
- * * it does not have its css property opacity set to 0
40
- * * its parent element is also visible (and so on up to the top of the DOM tree)
41
- * * it does not have the hidden attribute
42
- * * if `<details />` it has the open attribute
43
- * @example
44
- * <div
45
- * data-testid="zero-opacity"
46
- * style="opacity: 0"
47
- * >
48
- * Zero Opacity
49
- * </div>
50
- *
51
- * <div data-testid="visible">Visible Example</div>
52
- *
53
- * expect(getByTestId('zero-opacity')).not.toBeVisible()
54
- * expect(getByTestId('visible')).toBeVisible()
55
- * @see
56
- * [testing-library/jest-dom#tobevisible](https://github.com/testing-library/jest-dom#tobevisible)
57
- */
58
- toBeVisible(): R
59
- /**
60
- * @deprecated
61
- * since v5.9.0
62
- * @description
63
- * Assert whether an element has content or not.
64
- * @example
65
- * <span data-testid="not-empty">
66
- * <span data-testid="empty"></span>
67
- * </span>
68
- *
69
- * expect(getByTestId('empty')).toBeEmpty()
70
- * expect(getByTestId('not-empty')).not.toBeEmpty()
71
- * @see
72
- * [testing-library/jest-dom#tobeempty](https://github.com/testing-library/jest-dom#tobeempty)
73
- */
74
- toBeEmpty(): R
75
- /**
76
- * @description
77
- * Assert whether an element has content or not.
78
- * @example
79
- * <span data-testid="not-empty">
80
- * <span data-testid="empty"></span>
81
- * </span>
82
- *
83
- * expect(getByTestId('empty')).toBeEmptyDOMElement()
84
- * expect(getByTestId('not-empty')).not.toBeEmptyDOMElement()
85
- * @see
86
- * [testing-library/jest-dom#tobeemptydomelement](https://github.com/testing-library/jest-dom#tobeemptydomelement)
87
- */
88
- toBeEmptyDOMElement(): R
89
- /**
90
- * @description
91
- * Allows you to check whether an element is disabled from the user's perspective.
92
- *
93
- * Matches if the element is a form control and the `disabled` attribute is specified on this element or the
94
- * element is a descendant of a form element with a `disabled` attribute.
95
- * @example
96
- * <button
97
- * data-testid="button"
98
- * type="submit"
99
- * disabled
100
- * >
101
- * submit
102
- * </button>
103
- *
104
- * expect(getByTestId('button')).toBeDisabled()
105
- * @see
106
- * [testing-library/jest-dom#tobedisabled](https://github.com/testing-library/jest-dom#tobedisabled)
107
- */
108
- toBeDisabled(): R
109
- /**
110
- * @description
111
- * Allows you to check whether an element is not disabled from the user's perspective.
112
- *
113
- * Works like `not.toBeDisabled()`.
114
- *
115
- * Use this matcher to avoid double negation in your tests.
116
- * @example
117
- * <button
118
- * data-testid="button"
119
- * type="submit"
120
- * >
121
- * submit
122
- * </button>
123
- *
124
- * expect(getByTestId('button')).toBeEnabled()
125
- * @see
126
- * [testing-library/jest-dom#tobeenabled](https://github.com/testing-library/jest-dom#tobeenabled)
127
- */
128
- toBeEnabled(): R
129
- /**
130
- * @description
131
- * Check if a form element, or the entire `form`, is currently invalid.
132
- *
133
- * An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no
134
- * value or a value of "true", or if the result of `checkValidity()` is false.
135
- * @example
136
- * <input data-testid="no-aria-invalid" />
137
- *
138
- * <form data-testid="invalid-form">
139
- * <input required />
140
- * </form>
141
- *
142
- * expect(getByTestId('no-aria-invalid')).not.toBeInvalid()
143
- * expect(getByTestId('invalid-form')).toBeInvalid()
144
- * @see
145
- * [testing-library/jest-dom#tobeinvalid](https://github.com/testing-library/jest-dom#tobeinvalid)
146
- */
147
- toBeInvalid(): R
148
- /**
149
- * @description
150
- * This allows you to check if a form element is currently required.
151
- *
152
- * An element is required if it is having a `required` or `aria-required="true"` attribute.
153
- * @example
154
- * <input data-testid="required-input" required />
155
- * <div
156
- * data-testid="supported-role"
157
- * role="tree"
158
- * required />
159
- *
160
- * expect(getByTestId('required-input')).toBeRequired()
161
- * expect(getByTestId('supported-role')).not.toBeRequired()
162
- * @see
163
- * [testing-library/jest-dom#toberequired](https://github.com/testing-library/jest-dom#toberequired)
164
- */
165
- toBeRequired(): R
166
- /**
167
- * @description
168
- * Allows you to check if a form element is currently required.
169
- *
170
- * An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no
171
- * value or a value of "false", or if the result of `checkValidity()` is true.
172
- * @example
173
- * <input data-testid="aria-invalid" aria-invalid />
174
- *
175
- * <form data-testid="valid-form">
176
- * <input />
177
- * </form>
178
- *
179
- * expect(getByTestId('no-aria-invalid')).not.toBeValid()
180
- * expect(getByTestId('invalid-form')).toBeInvalid()
181
- * @see
182
- * [testing-library/jest-dom#tobevalid](https://github.com/testing-library/jest-dom#tobevalid)
183
- */
184
- toBeValid(): R
185
- /**
186
- * @description
187
- * Allows you to assert whether an element contains another element as a descendant or not.
188
- * @example
189
- * <span data-testid="ancestor">
190
- * <span data-testid="descendant"></span>
191
- * </span>
192
- *
193
- * const ancestor = getByTestId('ancestor')
194
- * const descendant = getByTestId('descendant')
195
- * const nonExistentElement = getByTestId('does-not-exist')
196
- * expect(ancestor).toContainElement(descendant)
197
- * expect(descendant).not.toContainElement(ancestor)
198
- * expect(ancestor).not.toContainElement(nonExistentElement)
199
- * @see
200
- * [testing-library/jest-dom#tocontainelement](https://github.com/testing-library/jest-dom#tocontainelement)
201
- */
202
- toContainElement(element: HTMLElement | SVGElement | null): R
203
- /**
204
- * @description
205
- * Assert whether a string representing a HTML element is contained in another element.
206
- * @example
207
- * <span data-testid="parent"><span data-testid="child"></span></span>
208
- *
209
- * expect(getByTestId('parent')).toContainHTML('<span data-testid="child"></span>')
210
- * @see
211
- * [testing-library/jest-dom#tocontainhtml](https://github.com/testing-library/jest-dom#tocontainhtml)
212
- */
213
- toContainHTML(htmlText: string): R
214
- /**
215
- * @description
216
- * Allows you to check if a given element has an attribute or not.
217
- *
218
- * You can also optionally check that the attribute has a specific expected value or partial match using
219
- * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring) or
220
- * [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
221
- * @example
222
- * <button
223
- * data-testid="ok-button"
224
- * type="submit"
225
- * disabled
226
- * >
227
- * ok
228
- * </button>
229
- *
230
- * expect(button).toHaveAttribute('disabled')
231
- * expect(button).toHaveAttribute('type', 'submit')
232
- * expect(button).not.toHaveAttribute('type', 'button')
233
- * @see
234
- * [testing-library/jest-dom#tohaveattribute](https://github.com/testing-library/jest-dom#tohaveattribute)
235
- */
236
- toHaveAttribute(attr: string, value?: unknown): R
237
- /**
238
- * @description
239
- * Check whether the given element has certain classes within its `class` attribute.
240
- *
241
- * You must provide at least one class, unless you are asserting that an element does not have any classes.
242
- * @example
243
- * <button
244
- * data-testid="delete-button"
245
- * class="btn xs btn-danger"
246
- * >
247
- * delete item
248
- * </button>
249
- *
250
- * <div data-testid="no-classes">no classes</div>
251
- *
252
- * const deleteButton = getByTestId('delete-button')
253
- * const noClasses = getByTestId('no-classes')
254
- * expect(deleteButton).toHaveClass('btn')
255
- * expect(deleteButton).toHaveClass('btn-danger xs')
256
- * expect(deleteButton).toHaveClass(/danger/, 'xs')
257
- * expect(deleteButton).toHaveClass('btn xs btn-danger', {exact: true})
258
- * expect(deleteButton).not.toHaveClass('btn xs btn-danger', {exact: true})
259
- * expect(noClasses).not.toHaveClass()
260
- * @see
261
- * [testing-library/jest-dom#tohaveclass](https://github.com/testing-library/jest-dom#tohaveclass)
262
- */
263
- toHaveClass(...classNames: (string | RegExp)[] | [string, options?: {exact: boolean}]): R
264
- /**
265
- * @description
266
- * This allows you to check whether the given form element has the specified displayed value (the one the
267
- * end user will see). It accepts <input>, <select> and <textarea> elements with the exception of <input type="checkbox">
268
- * and <input type="radio">, which can be meaningfully matched only using toBeChecked or toHaveFormValues.
269
- * @example
270
- * <label for="input-example">First name</label>
271
- * <input type="text" id="input-example" value="Luca" />
272
- *
273
- * <label for="textarea-example">Description</label>
274
- * <textarea id="textarea-example">An example description here.</textarea>
275
- *
276
- * <label for="single-select-example">Fruit</label>
277
- * <select id="single-select-example">
278
- * <option value="">Select a fruit...</option>
279
- * <option value="banana">Banana</option>
280
- * <option value="ananas">Ananas</option>
281
- * <option value="avocado">Avocado</option>
282
- * </select>
283
- *
284
- * <label for="multiple-select-example">Fruits</label>
285
- * <select id="multiple-select-example" multiple>
286
- * <option value="">Select a fruit...</option>
287
- * <option value="banana" selected>Banana</option>
288
- * <option value="ananas">Ananas</option>
289
- * <option value="avocado" selected>Avocado</option>
290
- * </select>
291
- *
292
- * const input = screen.getByLabelText('First name')
293
- * const textarea = screen.getByLabelText('Description')
294
- * const selectSingle = screen.getByLabelText('Fruit')
295
- * const selectMultiple = screen.getByLabelText('Fruits')
296
- *
297
- * expect(input).toHaveDisplayValue('Luca')
298
- * expect(textarea).toHaveDisplayValue('An example description here.')
299
- * expect(selectSingle).toHaveDisplayValue('Select a fruit...')
300
- * expect(selectMultiple).toHaveDisplayValue(['Banana', 'Avocado'])
301
- *
302
- * @see
303
- * [testing-library/jest-dom#tohavedisplayvalue](https://github.com/testing-library/jest-dom#tohavedisplayvalue)
304
- */
305
- toHaveDisplayValue(value: string | RegExp | Array<string | RegExp>): R
306
- /**
307
- * @description
308
- * Assert whether an element has focus or not.
309
- * @example
310
- * <div>
311
- * <input type="text" data-testid="element-to-focus" />
312
- * </div>
313
- *
314
- * const input = getByTestId('element-to-focus')
315
- * input.focus()
316
- * expect(input).toHaveFocus()
317
- * input.blur()
318
- * expect(input).not.toHaveFocus()
319
- * @see
320
- * [testing-library/jest-dom#tohavefocus](https://github.com/testing-library/jest-dom#tohavefocus)
321
- */
322
- toHaveFocus(): R
323
- /**
324
- * @description
325
- * Check if a form or fieldset contains form controls for each given name, and having the specified value.
326
- *
327
- * Can only be invoked on a form or fieldset element.
328
- * @example
329
- * <form data-testid="login-form">
330
- * <input type="text" name="username" value="jane.doe" />
331
- * <input type="password" name="password" value="123" />
332
- * <input type="checkbox" name="rememberMe" checked />
333
- * <button type="submit">Sign in</button>
334
- * </form>
335
- *
336
- * expect(getByTestId('login-form')).toHaveFormValues({
337
- * username: 'jane.doe',
338
- * rememberMe: true,
339
- * })
340
- * @see
341
- * [testing-library/jest-dom#tohaveformvalues](https://github.com/testing-library/jest-dom#tohaveformvalues)
342
- */
343
- toHaveFormValues(expectedValues: Record<string, unknown>): R
344
- /**
345
- * @description
346
- * Check if an element has specific css properties with specific values applied.
347
- *
348
- * Only matches if the element has *all* the expected properties applied, not just some of them.
349
- * @example
350
- * <button
351
- * data-testid="submit-button"
352
- * style="background-color: green; display: none"
353
- * >
354
- * submit
355
- * </button>
356
- *
357
- * const button = getByTestId('submit-button')
358
- * expect(button).toHaveStyle('background-color: green')
359
- * expect(button).toHaveStyle({
360
- * 'background-color': 'green',
361
- * display: 'none'
362
- * })
363
- * @see
364
- * [testing-library/jest-dom#tohavestyle](https://github.com/testing-library/jest-dom#tohavestyle)
365
- */
366
- toHaveStyle(css: string | Record<string, unknown>): R
367
- /**
368
- * @description
369
- * Check whether the given element has a text content or not.
370
- *
371
- * When a string argument is passed through, it will perform a partial case-sensitive match to the element
372
- * content.
373
- *
374
- * To perform a case-insensitive match, you can use a RegExp with the `/i` modifier.
375
- *
376
- * If you want to match the whole content, you can use a RegExp to do it.
377
- * @example
378
- * <span data-testid="text-content">Text Content</span>
379
- *
380
- * const element = getByTestId('text-content')
381
- * expect(element).toHaveTextContent('Content')
382
- * // to match the whole content
383
- * expect(element).toHaveTextContent(/^Text Content$/)
384
- * // to use case-insensitive match
385
- * expect(element).toHaveTextContent(/content$/i)
386
- * expect(element).not.toHaveTextContent('content')
387
- * @see
388
- * [testing-library/jest-dom#tohavetextcontent](https://github.com/testing-library/jest-dom#tohavetextcontent)
389
- */
390
- toHaveTextContent(
391
- text: string | RegExp,
392
- options?: {normalizeWhitespace: boolean},
393
- ): R
394
- /**
395
- * @description
396
- * Check whether the given form element has the specified value.
397
- *
398
- * Accepts `<input>`, `<select>`, and `<textarea>` elements with the exception of `<input type="checkbox">` and
399
- * `<input type="radiobox">`, which can be matched only using
400
- * [toBeChecked](https://github.com/testing-library/jest-dom#tobechecked) or
401
- * [toHaveFormValues](https://github.com/testing-library/jest-dom#tohaveformvalues).
402
- * @example
403
- * <input
404
- * type="number"
405
- * value="5"
406
- * data-testid="input-number" />
407
- *
408
- * const numberInput = getByTestId('input-number')
409
- * expect(numberInput).toHaveValue(5)
410
- * @see
411
- * [testing-library/jest-dom#tohavevalue](https://github.com/testing-library/jest-dom#tohavevalue)
412
- */
413
- toHaveValue(value?: string | string[] | number | null): R
414
- /**
415
- * @description
416
- * Assert whether the given element is checked.
417
- *
418
- * It accepts an `input` of type `checkbox` or `radio` and elements with a `role` of `radio` with a valid
419
- * `aria-checked` attribute of "true" or "false".
420
- * @example
421
- * <input
422
- * type="checkbox"
423
- * checked
424
- * data-testid="input-checkbox" />
425
- * <input
426
- * type="radio"
427
- * value="foo"
428
- * data-testid="input-radio" />
429
- *
430
- * const inputCheckbox = getByTestId('input-checkbox')
431
- * const inputRadio = getByTestId('input-radio')
432
- * expect(inputCheckbox).toBeChecked()
433
- * expect(inputRadio).not.toBeChecked()
434
- * @see
435
- * [testing-library/jest-dom#tobechecked](https://github.com/testing-library/jest-dom#tobechecked)
436
- */
437
- toBeChecked(): R
438
- /**
439
- * @deprecated
440
- * since v5.14.1
441
- * @description
442
- * Check the accessible description for an element.
443
- * This allows you to check whether the given element has a description or not.
444
- *
445
- * An element gets its description via the
446
- * [`aria-describedby` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute).
447
- * Set this to the `id` of one or more other elements. These elements may be nested
448
- * inside, be outside, or a sibling of the passed in element.
449
- *
450
- * Whitespace is normalized. Using multiple ids will
451
- * [join the referenced elements’ text content separated by a space](https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_description).
452
- *
453
- * When a `string` argument is passed through, it will perform a whole
454
- * case-sensitive match to the description text.
455
- *
456
- * To perform a case-insensitive match, you can use a `RegExp` with the `/i`
457
- * modifier.
458
- *
459
- * To perform a partial match, you can pass a `RegExp` or use
460
- * `expect.stringContaining("partial string")`.
461
- *
462
- * @example
463
- * <button aria-label="Close" aria-describedby="description-close">
464
- * X
465
- * </button>
466
- * <div id="description-close">
467
- * Closing will discard any changes
468
- * </div>
469
- *
470
- * <button>Delete</button>
471
- *
472
- * const closeButton = getByRole('button', {name: 'Close'})
473
- *
474
- * expect(closeButton).toHaveDescription('Closing will discard any changes')
475
- * expect(closeButton).toHaveDescription(/will discard/) // to partially match
476
- * expect(closeButton).toHaveDescription(expect.stringContaining('will discard')) // to partially match
477
- * expect(closeButton).toHaveDescription(/^closing/i) // to use case-insensitive match
478
- * expect(closeButton).not.toHaveDescription('Other description')
479
- *
480
- * const deleteButton = getByRole('button', {name: 'Delete'})
481
- * expect(deleteButton).not.toHaveDescription()
482
- * expect(deleteButton).toHaveDescription('') // Missing or empty description always becomes a blank string
483
- * @see
484
- * [testing-library/jest-dom#tohavedescription](https://github.com/testing-library/jest-dom#tohavedescription)
485
- */
486
- toHaveDescription(text?: string | RegExp | E): R
487
- /**
488
- * @description
489
- * This allows to assert that an element has the expected [accessible description](https://w3c.github.io/accname/).
490
- *
491
- * You can pass the exact string of the expected accessible description, or you can make a
492
- * partial match passing a regular expression, or by using either
493
- * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
494
- * or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
495
- * @example
496
- * <a data-testid="link" href="/" aria-label="Home page" title="A link to start over">Start</a>
497
- * <a data-testid="extra-link" href="/about" aria-label="About page">About</a>
498
- * <img src="avatar.jpg" data-testid="avatar" alt="User profile pic" />
499
- * <img src="logo.jpg" data-testid="logo" alt="Company logo" aria-describedby="t1" />
500
- * <span id="t1" role="presentation">The logo of Our Company</span>
501
- *
502
- * expect(getByTestId('link')).toHaveAccessibleDescription()
503
- * expect(getByTestId('link')).toHaveAccessibleDescription('A link to start over')
504
- * expect(getByTestId('link')).not.toHaveAccessibleDescription('Home page')
505
- * expect(getByTestId('extra-link')).not.toHaveAccessibleDescription()
506
- * expect(getByTestId('avatar')).not.toHaveAccessibleDescription()
507
- * expect(getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
508
- * expect(getByTestId('logo')).toHaveAccessibleDescription('The logo of Our Company')
509
- * @see
510
- * [testing-library/jest-dom#tohaveaccessibledescription](https://github.com/testing-library/jest-dom#tohaveaccessibledescription)
511
- */
512
- toHaveAccessibleDescription(text?: string | RegExp | E): R
5
+ export interface TestingLibraryMatchers<E, R> {
6
+ /**
7
+ * @description
8
+ * Assert whether an element is present in the document or not.
9
+ * @example
10
+ * <svg data-testid="svg-element"></svg>
11
+ *
12
+ * await expect.element(page.getByTestId('svg-element')).toBeInTheDocument()
13
+ * await expect.element(page.getByTestId('does-not-exist')).not.toBeInTheDocument()
14
+ * @see https://vitest.dev/guide/browser/assertion-api#tobeinthedocument
15
+ */
16
+ toBeInTheDocument(): R
17
+ /**
18
+ * @description
19
+ * This allows you to check if an element is currently visible to the user.
20
+ *
21
+ * An element is visible if **all** the following conditions are met:
22
+ * * it does not have its css property display set to none
23
+ * * it does not have its css property visibility set to either hidden or collapse
24
+ * * it does not have its css property opacity set to 0
25
+ * * its parent element is also visible (and so on up to the top of the DOM tree)
26
+ * * it does not have the hidden attribute
27
+ * * if `<details />` it has the open attribute
28
+ * @example
29
+ * <div
30
+ * data-testid="zero-opacity"
31
+ * style="opacity: 0"
32
+ * >
33
+ * Zero Opacity
34
+ * </div>
35
+ *
36
+ * <div data-testid="visible">Visible Example</div>
37
+ *
38
+ * await expect.element(page.getByTestId('zero-opacity')).not.toBeVisible()
39
+ * await expect.element(page.getByTestId('visible')).toBeVisible()
40
+ * @see https://vitest.dev/guide/browser/assertion-api#tobevisible
41
+ */
42
+ toBeVisible(): R
43
+ /**
44
+ * @description
45
+ * Assert whether an element has content or not.
46
+ * @example
47
+ * <span data-testid="not-empty">
48
+ * <span data-testid="empty"></span>
49
+ * </span>
50
+ *
51
+ * await expect.element(page.getByTestId('empty')).toBeEmptyDOMElement()
52
+ * await expect.element(page.getByTestId('not-empty')).not.toBeEmptyDOMElement()
53
+ * @see https://vitest.dev/guide/browser/assertion-api#tobeemptydomelement
54
+ */
55
+ toBeEmptyDOMElement(): R
56
+ /**
57
+ * @description
58
+ * Allows you to check whether an element is disabled from the user's perspective.
59
+ *
60
+ * Matches if the element is a form control and the `disabled` attribute is specified on this element or the
61
+ * element is a descendant of a form element with a `disabled` attribute.
62
+ * @example
63
+ * <button
64
+ * data-testid="button"
65
+ * type="submit"
66
+ * disabled
67
+ * >
68
+ * submit
69
+ * </button>
70
+ *
71
+ * await expect.element(page.getByTestId('button')).toBeDisabled()
72
+ * @see https://vitest.dev/guide/browser/assertion-api#tobedisabled
73
+ */
74
+ toBeDisabled(): R
75
+ /**
76
+ * @description
77
+ * Allows you to check whether an element is not disabled from the user's perspective.
78
+ *
79
+ * Works like `not.toBeDisabled()`.
80
+ *
81
+ * Use this matcher to avoid double negation in your tests.
82
+ * @example
83
+ * <button
84
+ * data-testid="button"
85
+ * type="submit"
86
+ * >
87
+ * submit
88
+ * </button>
89
+ *
90
+ * await expect.element(page.getByTestId('button')).toBeEnabled()
91
+ * @see https://vitest.dev/guide/browser/assertion-api#tobeenabled
92
+ */
93
+ toBeEnabled(): R
94
+ /**
95
+ * @description
96
+ * Check if a form element, or the entire `form`, is currently invalid.
97
+ *
98
+ * An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no
99
+ * value or a value of "true", or if the result of `checkValidity()` is false.
100
+ * @example
101
+ * <input data-testid="no-aria-invalid" />
102
+ *
103
+ * <form data-testid="invalid-form">
104
+ * <input required />
105
+ * </form>
106
+ *
107
+ * await expect(page.getByTestId('no-aria-invalid')).not.toBeInvalid()
108
+ * await expect(page.getByTestId('invalid-form')).toBeInvalid()
109
+ * @see https://vitest.dev/guide/browser/assertion-api#tobeinvalid
110
+ */
111
+ toBeInvalid(): R
112
+ /**
113
+ * @description
114
+ * This allows you to check if a form element is currently required.
115
+ *
116
+ * An element is required if it is having a `required` or `aria-required="true"` attribute.
117
+ * @example
118
+ * <input data-testid="required-input" required />
119
+ * <div
120
+ * data-testid="supported-role"
121
+ * role="tree"
122
+ * required />
123
+ *
124
+ * await expect.element(page.getByTestId('required-input')).toBeRequired()
125
+ * await expect.element(page.getByTestId('supported-role')).not.toBeRequired()
126
+ * @see https://vitest.dev/guide/browser/assertion-api#toberequired
127
+ */
128
+ toBeRequired(): R
129
+ /**
130
+ * @description
131
+ * Allows you to check if a form element is currently required.
132
+ *
133
+ * An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no
134
+ * value or a value of "false", or if the result of `checkValidity()` is true.
135
+ * @example
136
+ * <input data-testid="aria-invalid" aria-invalid />
137
+ *
138
+ * <form data-testid="valid-form">
139
+ * <input />
140
+ * </form>
141
+ *
142
+ * await expect.element(page.getByTestId('no-aria-invalid')).not.toBeValid()
143
+ * await expect.element(page.getByTestId('invalid-form')).toBeInvalid()
144
+ * @see https://vitest.dev/guide/browser/assertion-api#tobevalid
145
+ */
146
+ toBeValid(): R
147
+ /**
148
+ * @description
149
+ * Allows you to assert whether an element contains another element as a descendant or not.
150
+ * @example
151
+ * <span data-testid="ancestor">
152
+ * <span data-testid="descendant"></span>
153
+ * </span>
154
+ *
155
+ * const ancestor = page.getByTestId('ancestor')
156
+ * const descendant = page.getByTestId('descendant')
157
+ * const nonExistentElement = page.getByTestId('does-not-exist')
158
+ * await expect.element(ancestor).toContainElement(descendant)
159
+ * await expect.element(descendant).not.toContainElement(ancestor)
160
+ * await expect.element(ancestor).not.toContainElement(nonExistentElement)
161
+ * @see https://vitest.dev/guide/browser/assertion-api#tocontainelement
162
+ */
163
+ toContainElement(element: HTMLElement | SVGElement | null): R
164
+ /**
165
+ * @description
166
+ * Assert whether a string representing a HTML element is contained in another element.
167
+ * @example
168
+ * <span data-testid="parent"><span data-testid="child"></span></span>
169
+ *
170
+ * const parent = page.getByTestId('parent')
171
+ * await expect.element(parent).toContainHTML('<span data-testid="child"></span>')
172
+ * @see https://vitest.dev/guide/browser/assertion-api#tocontainhtml
173
+ */
174
+ toContainHTML(htmlText: string): R
175
+ /**
176
+ * @description
177
+ * Allows you to check if a given element has an attribute or not.
178
+ *
179
+ * You can also optionally check that the attribute has a specific expected value or partial match using
180
+ * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring) or
181
+ * [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
182
+ * @example
183
+ * <button
184
+ * data-testid="ok-button"
185
+ * type="submit"
186
+ * disabled
187
+ * >
188
+ * ok
189
+ * </button>
190
+ *
191
+ * await expect.element(button).toHaveAttribute('disabled')
192
+ * await expect.element(button).toHaveAttribute('type', 'submit')
193
+ * await expect.element(button).not.toHaveAttribute('type', 'button')
194
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveattribute
195
+ */
196
+ toHaveAttribute(attr: string, value?: unknown): R
197
+ /**
198
+ * @description
199
+ * Check whether the given element has certain classes within its `class` attribute.
200
+ *
201
+ * You must provide at least one class, unless you are asserting that an element does not have any classes.
202
+ * @example
203
+ * <button
204
+ * data-testid="delete-button"
205
+ * class="btn xs btn-danger"
206
+ * >
207
+ * delete item
208
+ * </button>
209
+ *
210
+ * <div data-testid="no-classes">no classes</div>
211
+ *
212
+ * const deleteButton = page.getByTestId('delete-button')
213
+ * const noClasses = page.getByTestId('no-classes')
214
+ * await expect.element(deleteButton).toHaveClass('btn')
215
+ * await expect.element(deleteButton).toHaveClass('btn-danger xs')
216
+ * await expect.element(deleteButton).toHaveClass(/danger/, 'xs')
217
+ * await expect.element(deleteButton).toHaveClass('btn xs btn-danger', {exact: true})
218
+ * await expect.element(deleteButton).not.toHaveClass('btn xs btn-danger', {exact: true})
219
+ * await expect.element(noClasses).not.toHaveClass()
220
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveclass
221
+ */
222
+ toHaveClass(...classNames:
223
+ | (string | RegExp)[]
224
+ | [string, options?: {exact: boolean}]
225
+ | [string, string, options?: {exact: boolean}]
226
+ | [string, string, string, options?: {exact: boolean}]
227
+ | [string, string, string, string, options?: {exact: boolean}]
228
+ | [string, string, string, string, string, options?: {exact: boolean}]
229
+ | [string, string, string, string, string, string, options?: {exact: boolean}]
230
+ | [string, string, string, string, string, string, string, options?: {exact: boolean}]
231
+ | [string, string, string, string, string, string, string, string, options?: {exact: boolean}]
232
+ | [string, string, string, string, string, string, string, string, string, options?: {exact: boolean}]
233
+ ): R
234
+ /**
235
+ * @description
236
+ * This allows you to check whether the given form element has the specified displayed value (the one the
237
+ * end user will see). It accepts <input>, <select> and <textarea> elements with the exception of <input type="checkbox">
238
+ * and <input type="radio">, which can be meaningfully matched only using toBeChecked or toHaveFormValues.
239
+ * @example
240
+ * <label for="input-example">First name</label>
241
+ * <input type="text" id="input-example" value="Luca" />
242
+ *
243
+ * <label for="textarea-example">Description</label>
244
+ * <textarea id="textarea-example">An example description here.</textarea>
245
+ *
246
+ * <label for="single-select-example">Fruit</label>
247
+ * <select id="single-select-example">
248
+ * <option value="">Select a fruit...</option>
249
+ * <option value="banana">Banana</option>
250
+ * <option value="ananas">Ananas</option>
251
+ * <option value="avocado">Avocado</option>
252
+ * </select>
253
+ *
254
+ * <label for="multiple-select-example">Fruits</label>
255
+ * <select id="multiple-select-example" multiple>
256
+ * <option value="">Select a fruit...</option>
257
+ * <option value="banana" selected>Banana</option>
258
+ * <option value="ananas">Ananas</option>
259
+ * <option value="avocado" selected>Avocado</option>
260
+ * </select>
261
+ *
262
+ * const input = page.getByLabelText('First name')
263
+ * const textarea = page.getByLabelText('Description')
264
+ * const selectSingle = page.getByLabelText('Fruit')
265
+ * const selectMultiple = page.getByLabelText('Fruits')
266
+ *
267
+ * await expect.element(input).toHaveDisplayValue('Luca')
268
+ * await expect.element(textarea).toHaveDisplayValue('An example description here.')
269
+ * await expect.element(selectSingle).toHaveDisplayValue('Select a fruit...')
270
+ * await expect.element(selectMultiple).toHaveDisplayValue(['Banana', 'Avocado'])
271
+ *
272
+ * @see https://vitest.dev/guide/browser/assertion-api#tohavedisplayvalue
273
+ */
274
+ toHaveDisplayValue(value: string | number | RegExp | Array<string | RegExp | number>): R
275
+ /**
276
+ * @description
277
+ * Assert whether an element has focus or not.
278
+ * @example
279
+ * <div>
280
+ * <input type="text" data-testid="element-to-focus" />
281
+ * </div>
282
+ *
283
+ * const input = page.getByTestId('element-to-focus')
284
+ * input.element().focus()
285
+ * await expect.element(input).toHaveFocus()
286
+ * input.element().blur()
287
+ * await expect.element(input).not.toHaveFocus()
288
+ * @see https://vitest.dev/guide/browser/assertion-api#tohavefocus
289
+ */
290
+ toHaveFocus(): R
291
+ /**
292
+ * @description
293
+ * Check if a form or fieldset contains form controls for each given name, and having the specified value.
294
+ *
295
+ * Can only be invoked on a form or fieldset element.
296
+ * @example
297
+ * <form data-testid="login-form">
298
+ * <input type="text" name="username" value="jane.doe" />
299
+ * <input type="password" name="password" value="123" />
300
+ * <input type="checkbox" name="rememberMe" checked />
301
+ * <button type="submit">Sign in</button>
302
+ * </form>
303
+ *
304
+ * await expect.element(page.getByTestId('login-form')).toHaveFormValues({
305
+ * username: 'jane.doe',
306
+ * rememberMe: true,
307
+ * })
308
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveformvalues
309
+ */
310
+ toHaveFormValues(expectedValues: Record<string, unknown>): R
311
+ /**
312
+ * @description
313
+ * Check if an element has specific css properties with specific values applied.
314
+ *
315
+ * Only matches if the element has *all* the expected properties applied, not just some of them.
316
+ * @example
317
+ * <button
318
+ * data-testid="submit-button"
319
+ * style="background-color: green; display: none"
320
+ * >
321
+ * submit
322
+ * </button>
323
+ *
324
+ * const button = page.getByTestId('submit-button')
325
+ * await expect.element(button).toHaveStyle('background-color: green')
326
+ * await expect.element(button).toHaveStyle({
327
+ * 'background-color': 'green',
328
+ * display: 'none'
329
+ * })
330
+ * @see https://vitest.dev/guide/browser/assertion-api#tohavestyle
331
+ */
332
+ toHaveStyle(css: string | Partial<CSSStyleDeclaration>): R
333
+ /**
334
+ * @description
335
+ * Check whether the given element has a text content or not.
336
+ *
337
+ * When a string argument is passed through, it will perform a partial case-sensitive match to the element
338
+ * content.
339
+ *
340
+ * To perform a case-insensitive match, you can use a RegExp with the `/i` modifier.
341
+ *
342
+ * If you want to match the whole content, you can use a RegExp to do it.
343
+ * @example
344
+ * <span data-testid="text-content">Text Content</span>
345
+ *
346
+ * const element = page.getByTestId('text-content')
347
+ * await expect.element(element).toHaveTextContent('Content')
348
+ * // to match the whole content
349
+ * await expect.element(element).toHaveTextContent(/^Text Content$/)
350
+ * // to use case-insensitive match
351
+ * await expect.element(element).toHaveTextContent(/content$/i)
352
+ * await expect.element(element).not.toHaveTextContent('content')
353
+ * @see https://vitest.dev/guide/browser/assertion-api#tohavetextcontent
354
+ */
355
+ toHaveTextContent(
356
+ text: string | number | RegExp,
357
+ options?: {normalizeWhitespace: boolean},
358
+ ): R
359
+ /**
360
+ * @description
361
+ * Check whether the given form element has the specified value.
362
+ *
363
+ * Accepts `<input>`, `<select>`, and `<textarea>` elements with the exception of `<input type="checkbox">` and
364
+ * `<input type="radiobox">`, which can be matched only using
365
+ * [toBeChecked](https://vitest.dev/guide/browser/assertion-api#tobechecked) or
366
+ * [toHaveFormValues](https://vitest.dev/guide/browser/assertion-api#tohaveformvalues).
367
+ * @example
368
+ * <input
369
+ * type="number"
370
+ * value="5"
371
+ * data-testid="input-number" />
372
+ *
373
+ * const numberInput = page.getByTestId('input-number')
374
+ * await expect.element(numberInput).toHaveValue(5)
375
+ * @see https://vitest.dev/guide/browser/assertion-api#tohavevalue
376
+ */
377
+ toHaveValue(value?: string | string[] | number | null): R
378
+ /**
379
+ * @description
380
+ * Assert whether the given element is checked.
381
+ *
382
+ * It accepts an `input` of type `checkbox` or `radio` and elements with a `role` of `radio` with a valid
383
+ * `aria-checked` attribute of "true" or "false".
384
+ * @example
385
+ * <input
386
+ * type="checkbox"
387
+ * checked
388
+ * data-testid="input-checkbox" />
389
+ * <input
390
+ * type="radio"
391
+ * value="foo"
392
+ * data-testid="input-radio" />
393
+ *
394
+ * const inputCheckbox = page.getByTestId('input-checkbox')
395
+ * const inputRadio = page.getByTestId('input-radio')
396
+ * await expect.element(inputCheckbox).toBeChecked()
397
+ * await expect.element(inputRadio).not.toBeChecked()
398
+ * @see https://vitest.dev/guide/browser/assertion-api#tobechecked
399
+ */
400
+ toBeChecked(): R
401
+ /**
402
+ * @description
403
+ * This allows to assert that an element has the expected [accessible description](https://w3c.github.io/accname/).
404
+ *
405
+ * You can pass the exact string of the expected accessible description, or you can make a
406
+ * partial match passing a regular expression, or by using either
407
+ * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
408
+ * or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
409
+ * @example
410
+ * <a data-testid="link" href="/" aria-label="Home page" title="A link to start over">Start</a>
411
+ * <a data-testid="extra-link" href="/about" aria-label="About page">About</a>
412
+ * <img src="avatar.jpg" data-testid="avatar" alt="User profile pic" />
413
+ * <img src="logo.jpg" data-testid="logo" alt="Company logo" aria-describedby="t1" />
414
+ * <span id="t1" role="presentation">The logo of Our Company</span>
415
+ *
416
+ * await expect.element(page.getByTestId('link')).toHaveAccessibleDescription()
417
+ * await expect.element(page.getByTestId('link')).toHaveAccessibleDescription('A link to start over')
418
+ * await expect.element(page.getByTestId('link')).not.toHaveAccessibleDescription('Home page')
419
+ * await expect.element(page.getByTestId('extra-link')).not.toHaveAccessibleDescription()
420
+ * await expect.element(page.getByTestId('avatar')).not.toHaveAccessibleDescription()
421
+ * await expect.element(page.getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
422
+ * await expect.element(page.getByTestId('logo')).toHaveAccessibleDescription('The logo of Our Company')
423
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveaccessibledescription
424
+ */
425
+ toHaveAccessibleDescription(text?: string | RegExp | E): R
513
426
 
514
- /**
515
- * @description
516
- * This allows you to assert that an element has the expected
517
- * [accessible error message](https://w3c.github.io/aria/#aria-errormessage).
518
- *
519
- * You can pass the exact string of the expected accessible error message.
520
- * Alternatively, you can perform a partial match by passing a regular expression
521
- * or by using either
522
- * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
523
- * or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
524
- *
525
- * @example
526
- * <input aria-label="Has Error" aria-invalid="true" aria-errormessage="error-message" />
527
- * <div id="error-message" role="alert">This field is invalid</div>
528
- *
529
- * <input aria-label="No Error Attributes" />
530
- * <input aria-label="Not Invalid" aria-invalid="false" aria-errormessage="error-message" />
531
- *
532
- * // Inputs with Valid Error Messages
533
- * expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage()
534
- * expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage('This field is invalid')
535
- * expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage(/invalid/i)
536
- * expect(
537
- * getByRole('textbox', {name: 'Has Error'}),
538
- * ).not.toHaveAccessibleErrorMessage('This field is absolutely correct!')
539
- *
540
- * // Inputs without Valid Error Messages
541
- * expect(
542
- * getByRole('textbox', {name: 'No Error Attributes'}),
543
- * ).not.toHaveAccessibleErrorMessage()
544
- *
545
- * expect(
546
- * getByRole('textbox', {name: 'Not Invalid'}),
547
- * ).not.toHaveAccessibleErrorMessage()
548
- *
549
- * @see
550
- * [testing-library/jest-dom#tohaveaccessibleerrormessage](https://github.com/testing-library/jest-dom#tohaveaccessibleerrormessage)
551
- */
552
- toHaveAccessibleErrorMessage(text?: string | RegExp | E): R
427
+ /**
428
+ * @description
429
+ * This allows you to assert that an element has the expected
430
+ * [accessible error message](https://w3c.github.io/aria/#aria-errormessage).
431
+ *
432
+ * You can pass the exact string of the expected accessible error message.
433
+ * Alternatively, you can perform a partial match by passing a regular expression
434
+ * or by using either
435
+ * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
436
+ * or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
437
+ *
438
+ * @example
439
+ * <input aria-label="Has Error" aria-invalid="true" aria-errormessage="error-message" />
440
+ * <div id="error-message" role="alert">This field is invalid</div>
441
+ *
442
+ * <input aria-label="No Error Attributes" />
443
+ * <input aria-label="Not Invalid" aria-invalid="false" aria-errormessage="error-message" />
444
+ *
445
+ * // Inputs with Valid Error Messages
446
+ * await expect.element(page.getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage()
447
+ * await expect.element(page.getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage('This field is invalid')
448
+ * await expect.element(page.getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage(/invalid/i)
449
+ * await expect.element(
450
+ * page.getByRole('textbox', {name: 'Has Error'}),
451
+ * ).not.toHaveAccessibleErrorMessage('This field is absolutely correct!')
452
+ *
453
+ * // Inputs without Valid Error Messages
454
+ * await expect.element(
455
+ * page.getByRole('textbox', {name: 'No Error Attributes'}),
456
+ * ).not.toHaveAccessibleErrorMessage()
457
+ *
458
+ * await expect.element(
459
+ * page.getByRole('textbox', {name: 'Not Invalid'}),
460
+ * ).not.toHaveAccessibleErrorMessage()
461
+ *
462
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveaccessibleerrormessage
463
+ */
464
+ toHaveAccessibleErrorMessage(text?: string | RegExp | E): R
553
465
 
554
- /**
555
- * @description
556
- * This allows to assert that an element has the expected [accessible name](https://w3c.github.io/accname/).
557
- * It is useful, for instance, to assert that form elements and buttons are properly labelled.
558
- *
559
- * You can pass the exact string of the expected accessible name, or you can make a
560
- * partial match passing a regular expression, or by using either
561
- * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
562
- * or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
563
- * @example
564
- * <img data-testid="img-alt" src="" alt="Test alt" />
565
- * <img data-testid="img-empty-alt" src="" alt="" />
566
- * <svg data-testid="svg-title"><title>Test title</title></svg>
567
- * <button data-testid="button-img-alt"><img src="" alt="Test" /></button>
568
- * <p><img data-testid="img-paragraph" src="" alt="" /> Test content</p>
569
- * <button data-testid="svg-button"><svg><title>Test</title></svg></p>
570
- * <div><svg data-testid="svg-without-title"></svg></div>
571
- * <input data-testid="input-title" title="test" />
572
- *
573
- * expect(getByTestId('img-alt')).toHaveAccessibleName('Test alt')
574
- * expect(getByTestId('img-empty-alt')).not.toHaveAccessibleName()
575
- * expect(getByTestId('svg-title')).toHaveAccessibleName('Test title')
576
- * expect(getByTestId('button-img-alt')).toHaveAccessibleName()
577
- * expect(getByTestId('img-paragraph')).not.toHaveAccessibleName()
578
- * expect(getByTestId('svg-button')).toHaveAccessibleName()
579
- * expect(getByTestId('svg-without-title')).not.toHaveAccessibleName()
580
- * expect(getByTestId('input-title')).toHaveAccessibleName()
581
- * @see
582
- * [testing-library/jest-dom#tohaveaccessiblename](https://github.com/testing-library/jest-dom#tohaveaccessiblename)
583
- */
584
- toHaveAccessibleName(text?: string | RegExp | E): R
585
- /**
586
- * @description
587
- * This allows you to assert that an element has the expected
588
- * [role](https://www.w3.org/TR/html-aria/#docconformance).
589
- *
590
- * This is useful in cases where you already have access to an element via
591
- * some query other than the role itself, and want to make additional
592
- * assertions regarding its accessibility.
593
- *
594
- * The role can match either an explicit role (via the `role` attribute), or
595
- * an implicit one via the [implicit ARIA
596
- * semantics](https://www.w3.org/TR/html-aria/).
597
- *
598
- * Note: roles are matched literally by string equality, without inheriting
599
- * from the ARIA role hierarchy. As a result, querying a superclass role
600
- * like 'checkbox' will not include elements with a subclass role like
601
- * 'switch'.
602
- *
603
- * @example
604
- * <button data-testid="button">Continue</button>
605
- * <div role="button" data-testid="button-explicit">Continue</button>
606
- * <button role="switch button" data-testid="button-explicit-multiple">Continue</button>
607
- * <a href="/about" data-testid="link">About</a>
608
- * <a data-testid="link-invalid">Invalid link<a/>
609
- *
610
- * expect(getByTestId('button')).toHaveRole('button')
611
- * expect(getByTestId('button-explicit')).toHaveRole('button')
612
- * expect(getByTestId('button-explicit-multiple')).toHaveRole('button')
613
- * expect(getByTestId('button-explicit-multiple')).toHaveRole('switch')
614
- * expect(getByTestId('link')).toHaveRole('link')
615
- * expect(getByTestId('link-invalid')).not.toHaveRole('link')
616
- * expect(getByTestId('link-invalid')).toHaveRole('generic')
617
- *
618
- * @see
619
- * [testing-library/jest-dom#tohaverole](https://github.com/testing-library/jest-dom#tohaverole)
620
- */
621
- toHaveRole(
622
- // Get autocomplete for ARIARole union types, while still supporting another string
623
- // Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
624
- role: ARIARole | (string & {}),
625
- ): R
626
- /**
627
- * @description
628
- * This allows you to check whether the given element is partially checked.
629
- * It accepts an input of type checkbox and elements with a role of checkbox
630
- * with a aria-checked="mixed", or input of type checkbox with indeterminate
631
- * set to true
632
- *
633
- * @example
634
- * <input type="checkbox" aria-checked="mixed" data-testid="aria-checkbox-mixed" />
635
- * <input type="checkbox" checked data-testid="input-checkbox-checked" />
636
- * <input type="checkbox" data-testid="input-checkbox-unchecked" />
637
- * <div role="checkbox" aria-checked="true" data-testid="aria-checkbox-checked" />
638
- * <div
639
- * role="checkbox"
640
- * aria-checked="false"
641
- * data-testid="aria-checkbox-unchecked"
642
- * />
643
- * <input type="checkbox" data-testid="input-checkbox-indeterminate" />
644
- *
645
- * const ariaCheckboxMixed = getByTestId('aria-checkbox-mixed')
646
- * const inputCheckboxChecked = getByTestId('input-checkbox-checked')
647
- * const inputCheckboxUnchecked = getByTestId('input-checkbox-unchecked')
648
- * const ariaCheckboxChecked = getByTestId('aria-checkbox-checked')
649
- * const ariaCheckboxUnchecked = getByTestId('aria-checkbox-unchecked')
650
- * const inputCheckboxIndeterminate = getByTestId('input-checkbox-indeterminate')
651
- *
652
- * expect(ariaCheckboxMixed).toBePartiallyChecked()
653
- * expect(inputCheckboxChecked).not.toBePartiallyChecked()
654
- * expect(inputCheckboxUnchecked).not.toBePartiallyChecked()
655
- * expect(ariaCheckboxChecked).not.toBePartiallyChecked()
656
- * expect(ariaCheckboxUnchecked).not.toBePartiallyChecked()
657
- *
658
- * inputCheckboxIndeterminate.indeterminate = true
659
- * expect(inputCheckboxIndeterminate).toBePartiallyChecked()
660
- * @see
661
- * [testing-library/jest-dom#tobepartiallychecked](https://github.com/testing-library/jest-dom#tobepartiallychecked)
662
- */
663
- toBePartiallyChecked(): R
664
- /**
665
- * @deprecated
666
- * since v5.17.0
667
- *
668
- * @description
669
- * Check whether the given element has an [ARIA error message](https://www.w3.org/TR/wai-aria/#aria-errormessage) or not.
670
- *
671
- * Use the `aria-errormessage` attribute to reference another element that contains
672
- * custom error message text. Multiple ids is **NOT** allowed. Authors MUST use
673
- * `aria-invalid` in conjunction with `aria-errormessage`. Learn more from the
674
- * [`aria-errormessage` spec](https://www.w3.org/TR/wai-aria/#aria-errormessage).
675
- *
676
- * Whitespace is normalized.
677
- *
678
- * When a `string` argument is passed through, it will perform a whole
679
- * case-sensitive match to the error message text.
680
- *
681
- * To perform a case-insensitive match, you can use a `RegExp` with the `/i`
682
- * modifier.
683
- *
684
- * To perform a partial match, you can pass a `RegExp` or use
685
- * expect.stringContaining("partial string")`.
686
- *
687
- * @example
688
- * <label for="startTime"> Please enter a start time for the meeting: </label>
689
- * <input id="startTime" type="text" aria-errormessage="msgID" aria-invalid="true" value="11:30 PM" />
690
- * <span id="msgID" aria-live="assertive" style="visibility:visible">
691
- * Invalid time: the time must be between 9:00 AM and 5:00 PM"
692
- * </span>
693
- *
694
- *
695
- * const timeInput = getByLabel('startTime')
696
- *
697
- * expect(timeInput).toHaveErrorMessage(
698
- * 'Invalid time: the time must be between 9:00 AM and 5:00 PM',
699
- * )
700
- * expect(timeInput).toHaveErrorMessage(/invalid time/i) // to partially match
701
- * expect(timeInput).toHaveErrorMessage(expect.stringContaining('Invalid time')) // to partially match
702
- * expect(timeInput).not.toHaveErrorMessage('Pikachu!')
703
- * @see
704
- * [testing-library/jest-dom#tohaveerrormessage](https://github.com/testing-library/jest-dom#tohaveerrormessage)
705
- */
706
- toHaveErrorMessage(text?: string | RegExp | E): R
707
- }
466
+ /**
467
+ * @description
468
+ * This allows to assert that an element has the expected [accessible name](https://w3c.github.io/accname/).
469
+ * It is useful, for instance, to assert that form elements and buttons are properly labelled.
470
+ *
471
+ * You can pass the exact string of the expected accessible name, or you can make a
472
+ * partial match passing a regular expression, or by using either
473
+ * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
474
+ * or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
475
+ * @example
476
+ * <img data-testid="img-alt" src="" alt="Test alt" />
477
+ * <img data-testid="img-empty-alt" src="" alt="" />
478
+ * <svg data-testid="svg-title"><title>Test title</title></svg>
479
+ * <button data-testid="button-img-alt"><img src="" alt="Test" /></button>
480
+ * <p><img data-testid="img-paragraph" src="" alt="" /> Test content</p>
481
+ * <button data-testid="svg-button"><svg><title>Test</title></svg></p>
482
+ * <div><svg data-testid="svg-without-title"></svg></div>
483
+ * <input data-testid="input-title" title="test" />
484
+ *
485
+ * await expect.element(page.getByTestId('img-alt')).toHaveAccessibleName('Test alt')
486
+ * await expect.element(page.getByTestId('img-empty-alt')).not.toHaveAccessibleName()
487
+ * await expect.element(page.getByTestId('svg-title')).toHaveAccessibleName('Test title')
488
+ * await expect.element(page.getByTestId('button-img-alt')).toHaveAccessibleName()
489
+ * await expect.element(page.getByTestId('img-paragraph')).not.toHaveAccessibleName()
490
+ * await expect.element(page.getByTestId('svg-button')).toHaveAccessibleName()
491
+ * await expect.element(page.getByTestId('svg-without-title')).not.toHaveAccessibleName()
492
+ * await expect.element(page.getByTestId('input-title')).toHaveAccessibleName()
493
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveaccessiblename
494
+ */
495
+ toHaveAccessibleName(text?: string | RegExp | E): R
496
+ /**
497
+ * @description
498
+ * This allows you to assert that an element has the expected
499
+ * [role](https://www.w3.org/TR/html-aria/#docconformance).
500
+ *
501
+ * This is useful in cases where you already have access to an element via
502
+ * some query other than the role itself, and want to make additional
503
+ * assertions regarding its accessibility.
504
+ *
505
+ * The role can match either an explicit role (via the `role` attribute), or
506
+ * an implicit one via the [implicit ARIA
507
+ * semantics](https://www.w3.org/TR/html-aria/).
508
+ *
509
+ * Note: roles are matched literally by string equality, without inheriting
510
+ * from the ARIA role hierarchy. As a result, querying a superclass role
511
+ * like 'checkbox' will not include elements with a subclass role like
512
+ * 'switch'.
513
+ *
514
+ * @example
515
+ * <button data-testid="button">Continue</button>
516
+ * <div role="button" data-testid="button-explicit">Continue</button>
517
+ * <button role="switch button" data-testid="button-explicit-multiple">Continue</button>
518
+ * <a href="/about" data-testid="link">About</a>
519
+ * <a data-testid="link-invalid">Invalid link<a/>
520
+ *
521
+ * await expect.element(page.getByTestId('button')).toHaveRole('button')
522
+ * await expect.element(page.getByTestId('button-explicit')).toHaveRole('button')
523
+ * await expect.element(page.getByTestId('button-explicit-multiple')).toHaveRole('button')
524
+ * await expect.element(page.getByTestId('button-explicit-multiple')).toHaveRole('switch')
525
+ * await expect.element(page.getByTestId('link')).toHaveRole('link')
526
+ * await expect.element(page.getByTestId('link-invalid')).not.toHaveRole('link')
527
+ * await expect.element(page.getByTestId('link-invalid')).toHaveRole('generic')
528
+ *
529
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaverole
530
+ */
531
+ toHaveRole(
532
+ // Get autocomplete for ARIARole union types, while still supporting another string
533
+ // Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
534
+ role: ARIARole | (string & {}),
535
+ ): R
536
+ /**
537
+ * @description
538
+ * This allows you to check whether the given element is partially checked.
539
+ * It accepts an input of type checkbox and elements with a role of checkbox
540
+ * with a aria-checked="mixed", or input of type checkbox with indeterminate
541
+ * set to true
542
+ *
543
+ * @example
544
+ * <input type="checkbox" aria-checked="mixed" data-testid="aria-checkbox-mixed" />
545
+ * <input type="checkbox" checked data-testid="input-checkbox-checked" />
546
+ * <input type="checkbox" data-testid="input-checkbox-unchecked" />
547
+ * <div role="checkbox" aria-checked="true" data-testid="aria-checkbox-checked" />
548
+ * <div
549
+ * role="checkbox"
550
+ * aria-checked="false"
551
+ * data-testid="aria-checkbox-unchecked"
552
+ * />
553
+ * <input type="checkbox" data-testid="input-checkbox-indeterminate" />
554
+ *
555
+ * const ariaCheckboxMixed = getByTestId('aria-checkbox-mixed')
556
+ * const inputCheckboxChecked = getByTestId('input-checkbox-checked')
557
+ * const inputCheckboxUnchecked = getByTestId('input-checkbox-unchecked')
558
+ * const ariaCheckboxChecked = getByTestId('aria-checkbox-checked')
559
+ * const ariaCheckboxUnchecked = getByTestId('aria-checkbox-unchecked')
560
+ * const inputCheckboxIndeterminate = getByTestId('input-checkbox-indeterminate')
561
+ *
562
+ * await expect.element(ariaCheckboxMixed).toBePartiallyChecked()
563
+ * await expect.element(inputCheckboxChecked).not.toBePartiallyChecked()
564
+ * await expect.element(inputCheckboxUnchecked).not.toBePartiallyChecked()
565
+ * await expect.element(ariaCheckboxChecked).not.toBePartiallyChecked()
566
+ * await expect.element(ariaCheckboxUnchecked).not.toBePartiallyChecked()
567
+ *
568
+ * inputCheckboxIndeterminate.indeterminate = true
569
+ * await expect.element(inputCheckboxIndeterminate).toBePartiallyChecked()
570
+ * @see https://vitest.dev/guide/browser/assertion-api#tobepartiallychecked
571
+ */
572
+ toBePartiallyChecked(): R
573
+ /**
574
+ * @description
575
+ * This allows to assert that an element has a
576
+ * [text selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection).
577
+ *
578
+ * This is useful to check if text or part of the text is selected within an
579
+ * element. The element can be either an input of type text, a textarea, or any
580
+ * other element that contains text, such as a paragraph, span, div etc.
581
+ *
582
+ * NOTE: the expected selection is a string, it does not allow to check for
583
+ * selection range indeces.
584
+ *
585
+ * @example
586
+ * <div>
587
+ * <input type="text" value="text selected text" data-testid="text" />
588
+ * <textarea data-testid="textarea">text selected text</textarea>
589
+ * <p data-testid="prev">prev</p>
590
+ * <p data-testid="parent">text <span data-testid="child">selected</span> text</p>
591
+ * <p data-testid="next">next</p>
592
+ * </div>
593
+ *
594
+ * page.getByTestId('text').element().setSelectionRange(5, 13)
595
+ * await expect.element(page.getByTestId('text')).toHaveSelection('selected')
596
+ *
597
+ * page.getByTestId('textarea').element().setSelectionRange(0, 5)
598
+ * await expect.element('textarea').toHaveSelection('text ')
599
+ *
600
+ * const selection = document.getSelection()
601
+ * const range = document.createRange()
602
+ * selection.removeAllRanges()
603
+ * selection.empty()
604
+ * selection.addRange(range)
605
+ *
606
+ * // selection of child applies to the parent as well
607
+ * range.selectNodeContents(page.getByTestId('child').element())
608
+ * await expect.element(page.getByTestId('child')).toHaveSelection('selected')
609
+ * await expect.element(page.getByTestId('parent')).toHaveSelection('selected')
610
+ *
611
+ * // selection that applies from prev all, parent text before child, and part child.
612
+ * range.setStart(page.getByTestId('prev').element(), 0)
613
+ * range.setEnd(page.getByTestId('child').element().childNodes[0], 3)
614
+ * await expect.element(page.queryByTestId('prev')).toHaveSelection('prev')
615
+ * await expect.element(page.queryByTestId('child')).toHaveSelection('sel')
616
+ * await expect.element(page.queryByTestId('parent')).toHaveSelection('text sel')
617
+ * await expect.element(page.queryByTestId('next')).not.toHaveSelection()
618
+ *
619
+ * // selection that applies from part child, parent text after child and part next.
620
+ * range.setStart(page.getByTestId('child').element().childNodes[0], 3)
621
+ * range.setEnd(page.getByTestId('next').element().childNodes[0], 2)
622
+ * await expect.element(page.queryByTestId('child')).toHaveSelection('ected')
623
+ * await expect.element(page.queryByTestId('parent')).toHaveSelection('ected text')
624
+ * await expect.element(page.queryByTestId('prev')).not.toHaveSelection()
625
+ * await expect.element(page.queryByTestId('next')).toHaveSelection('ne')
626
+ *
627
+ * @see https://vitest.dev/guide/browser/assertion-api#tohaveselection
628
+ */
629
+ toHaveSelection(selection?: string): R
708
630
  }
709
-
710
- // Needs to extend Record<string, any> to be accepted by expect.extend()
711
- // as it requires a string index signature.
712
- declare const matchers: matchers.TestingLibraryMatchers<any, void> &
713
- Record<string, any>
714
-
715
- declare namespace matchers$1 {
716
- export { matchers as default };
717
- }
718
-
719
- export { matchers$1 as default };