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

react-test-renderer: improve findByType() error message #17439

Merged

Conversation

henryqdineen
Copy link
Contributor

I noticed that The findByType() method throws unhelpful error messages when using a string as the type argument. For example:

testInstance.findByType('span');
// Expected 1 but found 2 instances with node type: "undefined"

I am also running into this when searching for components using React.memo. My solution was to use getComponentName(). Thanks!

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 23, 2019

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 72ff92a:

Sandbox Source
serene-hooks-5mgri Configuration

@sizebot
Copy link

sizebot commented Nov 23, 2019

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 72ff92a

@sizebot
Copy link

sizebot commented Nov 23, 2019

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 72ff92a

@stale
Copy link

stale bot commented Feb 21, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Feb 21, 2020
@henryqdineen
Copy link
Contributor Author

I still think this is a valid fix. Let me know if there is anything else needed from me.

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Feb 21, 2020
@threepointone
Copy link
Contributor

Could you rebase this and add a test for the Unknown branch? thanks!

…rns a falsy value. The error message in this case not the most descriptive but seems consistent with the `getComponentName(type) || 'Unknown'` pattern seen in multiple places in this code base.
@henryqdineen
Copy link
Contributor Author

Thanks @threepointone. I just rebased and added the suggested test.

@threepointone threepointone merged commit 053347e into facebook:master Feb 28, 2020
@threepointone
Copy link
Contributor

Looks good to me, thanks!

@henryqdineen henryqdineen deleted the find-by-type-error-message branch February 29, 2020 04:15
Copy link

@jen801 jen801 left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants