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: (getByText) more robust null/undefined check for text children #239

Merged
merged 2 commits into from
Jan 9, 2020

Conversation

hduprat
Copy link
Contributor

@hduprat hduprat commented Nov 26, 2019

Summary

When the number 0 is integrated into a component via a variable, getByText('0') does not find any Text instance.

Examples

Example.jsx:

const test = 0;
...
<Text>{test}</Text>

Example.test.jsx:

const testInstance = render(<Example/>);
getByText('0'); // throws whereas it should not, as there is a 0 in a text component

Test plan

A test has been added in render.test.js

// In some cases child might be undefined
child => (child ? child.toString() : '')
// In some cases child might be undefined or null
child => (child !== undefined && child !== null ? child.toString() : '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
child => (child !== undefined && child !== null ? child.toString() : '')
child => (child ?? child.toString() : '')

@thymikee thymikee merged commit 0840d44 into callstack:master Jan 9, 2020
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.

None yet

3 participants