From fe9e6653138189b9808557d1321591fd5728fd52 Mon Sep 17 00:00:00 2001 From: Paquitosoft Date: Fri, 1 Apr 2022 15:10:25 +0200 Subject: [PATCH 1/3] feat(byrole): Add description filter --- src/__tests__/role.js | 174 ++++++++++++++++++++++++++++++++++++++++++ src/queries/role.js | 36 ++++++++- src/role-helpers.js | 20 ++++- 3 files changed, 225 insertions(+), 5 deletions(-) diff --git a/src/__tests__/role.js b/src/__tests__/role.js index a87bc000..38fc2af1 100644 --- a/src/__tests__/role.js +++ b/src/__tests__/role.js @@ -572,3 +572,177 @@ test('should find the input using type property instead of attribute', () => { const {getByRole} = render('') expect(getByRole('textbox')).not.toBeNull() }) + +test('can be filtered by accessible description', () => { + const targetedNotificationMessage = 'Your session is about to expire!' + const {getByRole} = renderIntoDocument( + ` +`, + ) + + const notification = getByRole('alertdialog', { + description: targetedNotificationMessage, + }) + + expect(notification).not.toBeNull() + expect(notification).toHaveTextContent(targetedNotificationMessage) + + expect( + getQueriesForElement(notification).getByRole('button', {name: 'Close'}), + ).not.toBeNull() +}) + +test('error should include description when filtering a no results are found', () => { + const targetedNotificationMessage = 'Your session is about to expire!' + const {getByRole} = renderIntoDocument( + `
${targetedNotificationMessage}
`, + ) + + expect(() => + getByRole('alertdialog', {description: targetedNotificationMessage}), + ).toThrowErrorMatchingInlineSnapshot(` + Unable to find an accessible element with the role "alertdialog" and description "Your session is about to expire!" + + Here are the accessible roles: + + dialog: + + Name "": + Description "Your session is about to expire!": +
+ + -------------------------------------------------- + button: + + Name "Close": + Description "": +