// Disable automatic exports. import { ARIARole } from './aria-role.ts' export interface TestingLibraryMatchers { /** * @description * Assert whether an element is present in the document or not. * @example * * * await expect.element(page.getByTestId('svg-element')).toBeInTheDocument() * await expect.element(page.getByTestId('does-not-exist')).not.toBeInTheDocument() * @see https://vitest.dev/guide/browser/assertion-api#tobeinthedocument */ toBeInTheDocument(): R /** * @description * This allows you to check if an element is currently visible to the user. * * An element is visible if **all** the following conditions are met: * * it does not have its css property display set to none * * it does not have its css property visibility set to either hidden or collapse * * it does not have its css property opacity set to 0 * * its parent element is also visible (and so on up to the top of the DOM tree) * * it does not have the hidden attribute * * if `
` it has the open attribute * @example *
* Zero Opacity *
* *
Visible Example
* * await expect.element(page.getByTestId('zero-opacity')).not.toBeVisible() * await expect.element(page.getByTestId('visible')).toBeVisible() * @see https://vitest.dev/guide/browser/assertion-api#tobevisible */ toBeVisible(): R /** * @description * Assert whether an element has content or not. * @example * * * * * await expect.element(page.getByTestId('empty')).toBeEmptyDOMElement() * await expect.element(page.getByTestId('not-empty')).not.toBeEmptyDOMElement() * @see https://vitest.dev/guide/browser/assertion-api#tobeemptydomelement */ toBeEmptyDOMElement(): R /** * @description * Allows you to check whether an element is disabled from the user's perspective. * * Matches if the element is a form control and the `disabled` attribute is specified on this element or the * element is a descendant of a form element with a `disabled` attribute. * @example * * * await expect.element(page.getByTestId('button')).toBeDisabled() * @see https://vitest.dev/guide/browser/assertion-api#tobedisabled */ toBeDisabled(): R /** * @description * Allows you to check whether an element is not disabled from the user's perspective. * * Works like `not.toBeDisabled()`. * * Use this matcher to avoid double negation in your tests. * @example * * * await expect.element(page.getByTestId('button')).toBeEnabled() * @see https://vitest.dev/guide/browser/assertion-api#tobeenabled */ toBeEnabled(): R /** * @description * Check if a form element, or the entire `form`, is currently invalid. * * An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no * value or a value of "true", or if the result of `checkValidity()` is false. * @example * * *
* *
* * await expect(page.getByTestId('no-aria-invalid')).not.toBeInvalid() * await expect(page.getByTestId('invalid-form')).toBeInvalid() * @see https://vitest.dev/guide/browser/assertion-api#tobeinvalid */ toBeInvalid(): R /** * @description * This allows you to check if a form element is currently required. * * An element is required if it is having a `required` or `aria-required="true"` attribute. * @example * *
* * await expect.element(page.getByTestId('required-input')).toBeRequired() * await expect.element(page.getByTestId('supported-role')).not.toBeRequired() * @see https://vitest.dev/guide/browser/assertion-api#toberequired */ toBeRequired(): R /** * @description * Allows you to check if a form element is currently required. * * An `input`, `select`, `textarea`, or `form` element is invalid if it has an `aria-invalid` attribute with no * value or a value of "false", or if the result of `checkValidity()` is true. * @example * * *
* *
* * await expect.element(page.getByTestId('no-aria-invalid')).not.toBeValid() * await expect.element(page.getByTestId('invalid-form')).toBeInvalid() * @see https://vitest.dev/guide/browser/assertion-api#tobevalid */ toBeValid(): R /** * @description * Allows you to assert whether an element contains another element as a descendant or not. * @example * * * * * const ancestor = page.getByTestId('ancestor') * const descendant = page.getByTestId('descendant') * const nonExistentElement = page.getByTestId('does-not-exist') * await expect.element(ancestor).toContainElement(descendant) * await expect.element(descendant).not.toContainElement(ancestor) * await expect.element(ancestor).not.toContainElement(nonExistentElement) * @see https://vitest.dev/guide/browser/assertion-api#tocontainelement */ toContainElement(element: HTMLElement | SVGElement | null): R /** * @description * Assert whether a string representing a HTML element is contained in another element. * @example * * * const parent = page.getByTestId('parent') * await expect.element(parent).toContainHTML('') * @see https://vitest.dev/guide/browser/assertion-api#tocontainhtml */ toContainHTML(htmlText: string): R /** * @description * Allows you to check if a given element has an attribute or not. * * You can also optionally check that the attribute has a specific expected value or partial match using * [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring) or * [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp). * @example * * * await expect.element(button).toHaveAttribute('disabled') * await expect.element(button).toHaveAttribute('type', 'submit') * await expect.element(button).not.toHaveAttribute('type', 'button') * @see https://vitest.dev/guide/browser/assertion-api#tohaveattribute */ toHaveAttribute(attr: string, value?: unknown): R /** * @description * Check whether the given element has certain classes within its `class` attribute. * * You must provide at least one class, unless you are asserting that an element does not have any classes. * @example * * *
no classes
* * const deleteButton = page.getByTestId('delete-button') * const noClasses = page.getByTestId('no-classes') * await expect.element(deleteButton).toHaveClass('btn') * await expect.element(deleteButton).toHaveClass('btn-danger xs') * await expect.element(deleteButton).toHaveClass(/danger/, 'xs') * await expect.element(deleteButton).toHaveClass('btn xs btn-danger', {exact: true}) * await expect.element(deleteButton).not.toHaveClass('btn xs btn-danger', {exact: true}) * await expect.element(noClasses).not.toHaveClass() * @see https://vitest.dev/guide/browser/assertion-api#tohaveclass */ toHaveClass(...classNames: | (string | RegExp)[] | [string, options?: {exact: boolean}] | [string, string, options?: {exact: boolean}] | [string, string, string, options?: {exact: boolean}] | [string, string, string, string, options?: {exact: boolean}] | [string, string, string, string, string, options?: {exact: boolean}] | [string, string, string, string, string, string, options?: {exact: boolean}] | [string, string, string, string, string, string, string, options?: {exact: boolean}] | [string, string, string, string, string, string, string, string, options?: {exact: boolean}] | [string, string, string, string, string, string, string, string, string, options?: {exact: boolean}] ): R /** * @description * This allows you to check whether the given form element has the specified displayed value (the one the * end user will see). It accepts , * * * * * * * * const input = page.getByLabelText('First name') * const textarea = page.getByLabelText('Description') * const selectSingle = page.getByLabelText('Fruit') * const selectMultiple = page.getByLabelText('Fruits') * * await expect.element(input).toHaveDisplayValue('Luca') * await expect.element(textarea).toHaveDisplayValue('An example description here.') * await expect.element(selectSingle).toHaveDisplayValue('Select a fruit...') * await expect.element(selectMultiple).toHaveDisplayValue(['Banana', 'Avocado']) * * @see https://vitest.dev/guide/browser/assertion-api#tohavedisplayvalue */ toHaveDisplayValue(value: string | number | RegExp | Array): R /** * @description * Assert whether an element has focus or not. * @example *
* *
* * const input = page.getByTestId('element-to-focus') * input.element().focus() * await expect.element(input).toHaveFocus() * input.element().blur() * await expect.element(input).not.toHaveFocus() * @see https://vitest.dev/guide/browser/assertion-api#tohavefocus */ toHaveFocus(): R /** * @description * Check if a form or fieldset contains form controls for each given name, and having the specified value. * * Can only be invoked on a form or fieldset element. * @example *
* * * * *
* * await expect.element(page.getByTestId('login-form')).toHaveFormValues({ * username: 'jane.doe', * rememberMe: true, * }) * @see https://vitest.dev/guide/browser/assertion-api#tohaveformvalues */ toHaveFormValues(expectedValues: Record): R /** * @description * Check if an element has specific css properties with specific values applied. * * Only matches if the element has *all* the expected properties applied, not just some of them. * @example * * * const button = page.getByTestId('submit-button') * await expect.element(button).toHaveStyle('background-color: green') * await expect.element(button).toHaveStyle({ * 'background-color': 'green', * display: 'none' * }) * @see https://vitest.dev/guide/browser/assertion-api#tohavestyle */ toHaveStyle(css: string | Partial): R /** * @description * Check whether the given element has a text content or not. * * When a string argument is passed through, it will perform a partial case-sensitive match to the element * content. * * To perform a case-insensitive match, you can use a RegExp with the `/i` modifier. * * If you want to match the whole content, you can use a RegExp to do it. * @example * Text Content * * const element = page.getByTestId('text-content') * await expect.element(element).toHaveTextContent('Content') * // to match the whole content * await expect.element(element).toHaveTextContent(/^Text Content$/) * // to use case-insensitive match * await expect.element(element).toHaveTextContent(/content$/i) * await expect.element(element).not.toHaveTextContent('content') * @see https://vitest.dev/guide/browser/assertion-api#tohavetextcontent */ toHaveTextContent( text: string | number | RegExp, options?: {normalizeWhitespace: boolean}, ): R /** * @description * Check whether the given form element has the specified value. * * Accepts ``, ` *

prev

*

text selected text

*

next

*
* * page.getByTestId('text').element().setSelectionRange(5, 13) * await expect.element(page.getByTestId('text')).toHaveSelection('selected') * * page.getByTestId('textarea').element().setSelectionRange(0, 5) * await expect.element('textarea').toHaveSelection('text ') * * const selection = document.getSelection() * const range = document.createRange() * selection.removeAllRanges() * selection.empty() * selection.addRange(range) * * // selection of child applies to the parent as well * range.selectNodeContents(page.getByTestId('child').element()) * await expect.element(page.getByTestId('child')).toHaveSelection('selected') * await expect.element(page.getByTestId('parent')).toHaveSelection('selected') * * // selection that applies from prev all, parent text before child, and part child. * range.setStart(page.getByTestId('prev').element(), 0) * range.setEnd(page.getByTestId('child').element().childNodes[0], 3) * await expect.element(page.queryByTestId('prev')).toHaveSelection('prev') * await expect.element(page.queryByTestId('child')).toHaveSelection('sel') * await expect.element(page.queryByTestId('parent')).toHaveSelection('text sel') * await expect.element(page.queryByTestId('next')).not.toHaveSelection() * * // selection that applies from part child, parent text after child and part next. * range.setStart(page.getByTestId('child').element().childNodes[0], 3) * range.setEnd(page.getByTestId('next').element().childNodes[0], 2) * await expect.element(page.queryByTestId('child')).toHaveSelection('ected') * await expect.element(page.queryByTestId('parent')).toHaveSelection('ected text') * await expect.element(page.queryByTestId('prev')).not.toHaveSelection() * await expect.element(page.queryByTestId('next')).toHaveSelection('ne') * * @see https://vitest.dev/guide/browser/assertion-api#tohaveselection */ toHaveSelection(selection?: string): R }