diff --git a/README.md b/README.md index bd2394b..c2bacce 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ clear to read and to maintain. - [`toHaveRole`](#tohaverole) - [`toHaveErrorMessage`](#tohaveerrormessage) - [`toBePressed`](#tobepressed) + - [`toBePartiallyPressed`](#tobepartiallypressed) - [Deprecated matchers](#deprecated-matchers) - [`toBeEmpty`](#tobeempty) - [`toBeInTheDOM`](#tobeinthedom) @@ -1347,6 +1348,44 @@ screen.getByRole('button', {name: 'Pressed span'}).toBePressed() screen.getByRole('button', {name: 'Released span'}).not.toBePressed() ``` +
+ +### `toBePartiallyPressed` + +This allows to check whether given element is partially +[pressed](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-pressed). + +It accepts elements with explicit or implicit `button` role and valid +`aria-pressed` attribute of `mixed`. + +```typescript +toBePressed() +``` + +#### Examples + +```html + + +Partially pressed span +``` + +##### Using DOM Testing Library + +```javascript +screen.getByRole('button', {name: 'Partially pressed'}).toBePartiallyPressed() +screen + .getByRole('button', {name: 'Partially pressed input button'}) + .toBePartiallyPressed() +screen + .getByRole('button', {name: 'Partially pressed span'}) + .toBePartiallyPressed() +``` + ## Deprecated matchers ### `toBeEmpty` diff --git a/src/__tests__/to-be-partially-pressed.js b/src/__tests__/to-be-partially-pressed.js new file mode 100644 index 0000000..da6e7fe --- /dev/null +++ b/src/__tests__/to-be-partially-pressed.js @@ -0,0 +1,111 @@ +import {render} from './helpers/test-utils' + +describe('.toBePartiallyPressed', () => { + test('handles button element', () => { + const {queryByTestId} = render(` + @@ -774,16 +774,16 @@ declare namespace matchers { * * * - * + * * Pressed span * Released span * * screen.getByRole('button', { name: 'Pressed' }).toBePressed(); * screen.getByRole('button', { name: 'Released' }).not.toBePressed(); - * + * * screen.getByRole('button', { name: 'Pressed input button' }).toBePressed(); * screen.getByRole('button', { name: 'Released input button' }).not.toBePressed(); - * + * * screen.getByRole('button', { name: 'Pressed span' }).toBePressed(); * screen.getByRole('button', { name: 'Released span' }).not.toBePressed(); * @@ -791,6 +791,25 @@ declare namespace matchers { * [testing-library/jest-dom#tobepressed](https://github.com/testing-library/jest-dom#tobepressed) */ toBePressed(): R + /* + * @description + * This allows to check whether given element has been [partially pressed](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-pressed) + * + * It accepts elements with explicit or implicit `button` role and valid `aria-pressed` of `"mixed"`. + * + * @example + * + * + * Partially pressed span + * + * screen.getByRole('button', { name: 'Partially Pressed' }).toBePartiallyPressed(); + * screen.getByRole('button', { name: 'Partially pressed input button' }).toBePartiallyPressed(); + * screen.getByRole('button', { name: 'Partially pressed span' }).toBePartiallyPressed(); + * + * @See + * [testing-library/jest-dom#tobepartiallypressed](https://github.com/testing-library/jest-dom#tobepartiallypressed) + */ + toBePartiallyPressed(): R } }