question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected behavior for <Text /> element

See original GitHub issue

In React Native it is okay to pass a number as a child for a <Text /> element. So

<Text>2<Text />

is the same as

<Text>{"2"}<Text />

or

<Text>2.toString()<Text />

But since getByText only accepts a string as it’s input, you can’t find the element if it’s being rendered in the first way.

This took me quite some time to debug and I think it’s very counter-intuitive. Maybe there is a good solution so getByText finds everything rendered between <Text /> tags?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
janhesterscommented, Dec 3, 2018

~~I tried that way, too ~~

const amountRegex = new RegExp(props.amount.toString());
expect(getByText(amountRegex)).toBeDefined();

and still the component isn’t found.

I’m sorry, I’m dumb, this works. Thank you a lot!

If someone in the future sees that: If you have a prop named amount make sure to use it like this:

<Text>{this.props.amount}</ Text>

instead of this:

<Text>this.props.amount</ Text>

Otherwise the regex above will not find it 😄

0reactions
thymikeecommented, Dec 3, 2018

Awesome you made it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing the text node of an element - unexpected behavior (for ...
I'm trying to access the text of some elements using jquery, but it seems that once the text is accessed, it is removed...
Read more >
Unexpected behavior with inline-block - Stack Overflow
You made your element to behave like an inline element so there is no more line break and thus you will have this...
Read more >
SharePoint 2010 rich-text editor unexpected behavior
In Microsoft Word, a newline immediately following a heading reverts to normal text. The same is true of the RTE in Google Docs....
Read more >
Unexpected Behavior of Text Input node - Dashboard
The issue arises when the user stops the reaction, or tries to modify a parameter. When this happens, only the modified value is...
Read more >
oxy_textArea Unexpected Behavior/Not Working in Oxygen ...
As far as I understand you use the textfield to edit the value of an attribute, and for some reason the text content...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found