From eeebfc2aac112575561aef71b78d7c828c3f0fac Mon Sep 17 00:00:00 2001 From: eps1lon Date: Wed, 8 Mar 2023 17:10:31 +0100 Subject: [PATCH] feat(ByRole): Allow filter by disabled state --- src/__tests__/ariaAttributes.js | 54 +++++++++++++++++++++++++++++++++ src/queries/role.ts | 15 +++++++++ src/role-helpers.js | 24 +++++++++++++++ types/queries.d.ts | 5 +++ 4 files changed, 98 insertions(+) diff --git a/src/__tests__/ariaAttributes.js b/src/__tests__/ariaAttributes.js index 1ceb210d..2f19840c 100644 --- a/src/__tests__/ariaAttributes.js +++ b/src/__tests__/ariaAttributes.js @@ -258,3 +258,57 @@ test('`expanded: true|false` matches `expanded` elements with proper role', () = expect(getByRole('button', {expanded: true})).toBeInTheDocument() expect(getByRole('button', {expanded: false})).toBeInTheDocument() }) + +test('`disabled` throws on unsupported roles', () => { + const {getByRole} = render( + `
Hello, Dave!
`, + ) + expect(() => + getByRole('alert', {disabled: true}), + ).toThrowErrorMatchingInlineSnapshot( + `"aria-disabled" is not supported on role "alert".`, + ) +}) + +test('`disabled: true|false` matches `disabled` buttons', () => { + const {getByRole} = renderIntoDocument( + `
+
`, + ) + expect(getByRole('button', {disabled: true})).toBeInTheDocument() + expect(getByRole('button', {disabled: false})).toBeInTheDocument() +}) + +test('`disabled: true|false` matches `aria-disabled` buttons', () => { + const {getByRole} = renderIntoDocument( + `
+
`, + ) + expect(getByRole('button', {disabled: true})).toBeInTheDocument() + expect(getByRole('button', {disabled: false})).toBeInTheDocument() +}) + +test('`disabled` attributes overrides `aria-dsiabled`', () => { + const {getByRole} = renderIntoDocument( + `
+
`, + ) + expect(getByRole('button', {disabled: true})).toBeInTheDocument() +}) + +test('consider `disabled` attribute only if supported', () => { + const {getByRole, queryByRole} = renderIntoDocument( + `
+