Skip to content
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

fix: not similar behaviour of ByLabelText and ByRole queries with nbsp in DOM (fix #890, #904) #946

Conversation

savcni01
Copy link
Contributor

@savcni01 savcni01 commented May 5, 2021

According to the fix #904 issue - getByRole fails if filtering by accessible name with   in it

Probably this PR also can fix #890

If we have   at label name then
ByLabelText('text with nbsp') and ByRole('textbox', {name: 'text with nbsp'}) queries behave differently
This PR will solve an issue by sync behavior.

Currently, as the first step of solutions representing tests showing different behavior are added.

Checklist:

  • Documentation added to the - "N/A"
    docs site
  • Tests
  • Typescript definitions updated - "N/A"
  • Ready to be merged

…and `ByRole` queries

  - first step to fix testing-library#904 - not similar behaviour of `ByLabelText` and `ByRole, {name: ''}` with nbsp at DOM
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 5, 2021

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 36faca6:

Sandbox Source
react-testing-library-examples Configuration
sleepy-drake-0n8ss Issue #890
react-testing-library demo Issue #890
react-testing-library demo (forked) Issue #904

…queries in we have nbsp

  - by adding to byRole the same Normalizer we are using at ByLabelText
@savcni01 savcni01 changed the title WIP: fix: not similar behaviour of ByLabelText and ByRole queries with nbsp in DOM fix: not similar behaviour of ByLabelText and ByRole queries with nbsp in DOM May 5, 2021
@savcni01 savcni01 changed the title fix: not similar behaviour of ByLabelText and ByRole queries with nbsp in DOM fix: not similar behaviour of ByLabelText and ByRole queries with nbsp in DOM (fix #890, #904) May 5, 2021
@@ -153,7 +153,7 @@ function queryAllByRole(
}),
element,
name,
text => text,
matchNormalizer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What else does matchNormalizer do? If you just want to fix nbsp then we should make this explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to request at issue matchNormalizer - here sync behavior for ByLabelText and ByRole.
the idea that we'll have the same behavior/results for the same inputs.

@codecov
Copy link

codecov bot commented May 10, 2021

Codecov Report

Merging #946 (36faca6) into main (c273ed5) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #946   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          966       965    -1     
  Branches       293       293           
=========================================
- Hits           966       965    -1     
Flag Coverage Δ
node-10.14.2 100.00% <ø> (ø)
node-12 100.00% <ø> (ø)
node-14 100.00% <ø> (ø)
node-15 100.00% <ø> (ø)
node-16 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/queries/role.js 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c273ed5...36faca6. Read the comment docs.

@eps1lon
Copy link
Member

eps1lon commented Aug 25, 2021

See #904 (comment)

@eps1lon eps1lon closed this Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getByRole doesn't normalize the node text getByRole fails if filtering by accessible name with &nbsp; in it
2 participants