Extra space added around embedded expressions in JSX when querying by role + name
See original GitHub issue@testing-library/dom
version: 7.5.9- Testing Framework and version: jest 25.5.4
- DOM Environment: jsdom
Relevant code or config:
export default ({ name }) => <h1>Hello {name}!</h1>;
screen.getByRole("heading", { name: /Hello Jill!/i })
What you did:
Tried to query an element by role + name
What happened:
The existing element cannot be found. If the name is in JSX with an embedded expression, potentially inexistent spaces are added around it:
Unable to find an accessible element with the role "heading" and name `/Hello Jill!/i`
Here are the accessible roles:
heading:
Name "Hello Jill !":
<h1 />
Note the extra space here:
Name "Hello Jill !":
^
Reproduction:
https://codesandbox.io/s/react-testing-library-demo-09wqi
Problem description:
I cannot create accurate queries in those cases (embedded expressions without surrounding space)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Best practice when adding whitespace in JSX - Stack Overflow
To add a space via JSX, simply put a string consisting of one space character in a JSX expression. The simplest way to...
Read more >Render a String with Non-breaking Spaces in React | Pluralsight
If your JSX element is such that the white spaces are equivalent to empty spaces in the string, you can simply set this...
Read more >What are inline conditional expressions in ReactJS
In this tutorial, we will go through the concept of inline conditional rendering in React. As the inline condition suggests, we can write...
Read more >Understanding Template Literals in JavaScript - DigitalOcean
With template literals, an expression can be embedded in a placeholder. A placeholder is represented by ${} , with anything within the curly ......
Read more >JSX in React – Explained with Examples - freeCodeCamp
JSX Expressions, which are written inside curly brackets, allow only things that evaluate to some value like string, number, array map method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Awesome! Such a quick reply and fix! Thank you folks! I did check the CodeSandbox of the PR and it does work as expected ^__^
🎉 This issue has been resolved in version 7.10.1 🎉
The release is available on:
npm package (@latest dist-tag)
Your semantic-release bot 📦🚀