Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion types/testing-library__jest-dom/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for @testing-library/jest-dom 5.9
// Type definitions for @testing-library/jest-dom 5.13
// Project: https://github.com/testing-library/jest-dom
// Definitions by: Ernesto García <https://github.com/gnapse>
// John Gozde <https://github.com/jgoz>
Expand Down Expand Up @@ -523,5 +523,46 @@ declare namespace jest {
* [testing-library/jest-dom#tobepartiallychecked](https:github.com/testing-library/jest-dom#tobepartiallychecked)
*/
toBePartiallyChecked(): R;
/**
* @description
*
* Check whether the given element has an [ARIA error message](https://www.w3.org/TR/wai-aria/#aria-errormessage) or not.
*
* Use the `aria-errormessage` attribute to reference another element that contains
* custom error message text. Multiple ids is **NOT** allowed. Authors MUST use
* `aria-invalid` in conjunction with `aria-errormessage`. Learn more from the
* [`aria-errormessage` spec](https://www.w3.org/TR/wai-aria/#aria-errormessage).
*
* Whitespace is normalized.
*
* When a `string` argument is passed through, it will perform a whole
* case-sensitive match to the error message text.
*
* To perform a case-insensitive match, you can use a `RegExp` with the `/i`
* modifier.
*
* To perform a partial match, you can pass a `RegExp` or use
* expect.stringContaining("partial string")`.
*
* @example
* <label for="startTime"> Please enter a start time for the meeting: </label>
* <input id="startTime" type="text" aria-errormessage="msgID" aria-invalid="true" value="11:30 PM" />
* <span id="msgID" aria-live="assertive" style="visibility:visible">
* Invalid time: the time must be between 9:00 AM and 5:00 PM"
* </span>
*
*
* const timeInput = getByLabel('startTime')
*
* expect(timeInput).toHaveErrorMessage(
* 'Invalid time: the time must be between 9:00 AM and 5:00 PM',
* )
* expect(timeInput).toHaveErrorMessage(/invalid time/i) // to partially match
* expect(timeInput).toHaveErrorMessage(expect.stringContaining('Invalid time')) // to partially match
* expect(timeInput).not.toHaveErrorMessage('Pikachu!')
* @see
* [testing-library/jest-dom#tohaveerrormessage](https:github.com/testing-library/jest-dom#tohaveerrormessage)
*/
toHaveErrorMessage(text?: string | RegExp | ReturnType<typeof expect.stringContaining>): R;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ expect(element).toHaveDescription('some description');
expect(element).toHaveDescription(/some description/);
expect(element).toHaveDescription(expect.stringContaining('partial'));
expect(element).toHaveDescription();
expect(element).toHaveErrorMessage('Invalid time: the time must be between 9:00 AM and 5:00 PM');
expect(element).toHaveErrorMessage(/invalid time/i);
expect(element).toHaveErrorMessage(expect.stringContaining('Invalid time'));

expect(element).not.toBeInTheDOM();
expect(element).not.toBeInTheDOM(document.body);
Expand Down Expand Up @@ -83,3 +86,5 @@ expect(element).not.toBeChecked();
expect(element).not.toHaveDescription('some description');
expect(element).not.toHaveDescription();
expect(element).not.toBePartiallyChecked();
expect(element).not.toHaveErrorMessage();
expect(element).not.toHaveErrorMessage('Pikachu!');