-
Notifications
You must be signed in to change notification settings - Fork 469
feat(ByRole): Add support for fallback roles #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ByRole): Add support for fallback roles #418
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 97141f7:
|
Codecov Report
@@ Coverage Diff @@
## master #418 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 22 22
Lines 374 381 +7
Branches 87 89 +2
=====================================
+ Hits 374 381 +7
Continue to review full report at Codecov.
|
@kentcdodds Since this is my first PR I need some guidance to merge it ASAP. I am aware of that I have to update the docs. I'm not sure whether to create the PR for it before the merge of the changes or after it Please let me know if I missed something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Great job! Just a few comments. Let me know if you have any questions.
@@ -433,6 +434,7 @@ test('queryAllByRole returns semantic html elements', () => { | |||
expect(queryAllByRole(/rowgroup/i)).toHaveLength(2) | |||
expect(queryAllByRole(/(table)|(textbox)/i)).toHaveLength(3) | |||
expect(queryAllByRole(/img/i)).toHaveLength(1) | |||
expect(queryAllByRole('progressbar', {queryFallbacks: true})).toHaveLength(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(queryAllByRole('progressbar', {queryFallbacks: true})).toHaveLength(1) | |
expect(queryAllByRole('meter')).toHaveLength(1) | |
expect(queryAllByRole('progressbar')).toHaveLength(0) | |
expect(queryAllByRole('progressbar', {queryFallbacks: true})).toHaveLength(1) |
@@ -482,6 +485,7 @@ test('getAll* matchers return an array', () => { | |||
expect(getAllByDisplayValue(/cars$/)).toHaveLength(2) | |||
expect(getAllByText(/^where/i)).toHaveLength(1) | |||
expect(getAllByRole(/container/i)).toHaveLength(1) | |||
expect(getAllByRole('progressbar', {queryFallbacks: true})).toHaveLength(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(getAllByRole('progressbar', {queryFallbacks: true})).toHaveLength(1) | |
expect(getAllByRole('meter')).toHaveLength(1) | |
expect(getAllByRole('progressbar', {queryFallbacks: true})).toHaveLength(1) |
await expect( | ||
findByRole('progressbar', {queryFallbacks: true}), | ||
).resolves.toBeTruthy() | ||
await expect( | ||
findAllByRole('progressbar', {queryFallbacks: true}), | ||
).resolves.toHaveLength(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't make a suggestion in GitHub for this, but I would suggest this change to:
await expect(findByRole('meter')).resolves.toBeTruthy()
await expect(findAllByRole('meter')).resolves.toHaveLength(1)
await expect(findByRole('progressbar', {queryFallbacks: true})).resolves.toBeTruthy()
await expect(findAllByRole('progressbar', {queryFallbacks: true})).resolves.toHaveLength(1)
Thanks!
Also, sorry that it took me so long to get to this. I took a little break 😅 Thanks for your work! |
Welcome back from holidays, Kent. I hope it went well. Thanks for the review. I have lost some track on this, but I'll push the suggested changes ASAP. |
@kentcdodds I have made the review changes. |
.some(text => matcher(text, node, role, matchNormalizer)) | ||
} | ||
// if a custom normalizer is passed then let normalizer handle the role value | ||
if (normalizer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a test specifically covering this case? We should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it is covered in text-matcher.js.
If this is not the test case you're talking about then can you please guide me where to add the test case for it? That will be very helpful :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kentcdodds ping you to remind again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. That's fine. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Could you add one test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thank you for your help on this @iAziz786!
Could you make a pull request to add this to the docs please? https://github.com/testing-library/testing-library-docs |
@all-contributors please add @iAziz786 code and tests |
I've put up a pull request to add @iAziz786! 🎉 |
🎉 This PR is included in version 6.12.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Yes, @kentcdodds, I'll surely add this to the docs. I need a little time. |
What: Adding support for
*ByRole
query to query multiple roles.Why:
Closes: #411
How: With the help of a flag named
queryFallbacks
,*ByRole
queries can query multiple roles. If the flag is missing and you're trying to query a role that is located on the right side, then this will throw an error. The working is same as mentioned in (#411 (comment))Checklist:
docs site
DefinitelyTyped (I'm not sure whether it's needed or not)