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

@henryqdineen henryqdineen commented Nov 23, 2019

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
Copy link

@codesandbox codesandbox 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 sizebot commented Nov 23, 2019

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 72ff92a

@sizebot
Copy link

@sizebot sizebot commented Nov 23, 2019

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 72ff92a

@stale
Copy link

@stale 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 label Feb 21, 2020
@henryqdineen
Copy link
Contributor Author

@henryqdineen henryqdineen commented Feb 21, 2020

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 label Feb 21, 2020
@henryqdineen henryqdineen requested a review from gaearon Feb 21, 2020
@threepointone
Copy link
Contributor

@threepointone threepointone commented Feb 28, 2020

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 henryqdineen force-pushed the henryqdineen:find-by-type-error-message branch from 278787b to 72ff92a Feb 28, 2020
@henryqdineen
Copy link
Contributor Author

@henryqdineen henryqdineen commented Feb 28, 2020

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

@threepointone threepointone merged commit 053347e into facebook:master Feb 28, 2020
23 checks passed
23 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: build_devtools_and_process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: build_experimental Your tests passed on CircleCI!
Details
ci/circleci: flow Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: lint_build Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts Your tests passed on CircleCI!
Details
ci/circleci: process_artifacts_experimental Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: sizebot Your tests passed on CircleCI!
Details
ci/circleci: sizebot_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_build Your tests passed on CircleCI!
Details
ci/circleci: test_build_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_build_prod Your tests passed on CircleCI!
Details
ci/circleci: test_build_prod_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_devtools Your tests passed on CircleCI!
Details
ci/circleci: test_dom_fixtures Your tests passed on CircleCI!
Details
ci/circleci: test_source Your tests passed on CircleCI!
Details
ci/circleci: test_source_experimental Your tests passed on CircleCI!
Details
ci/circleci: test_source_persistent Your tests passed on CircleCI!
Details
ci/circleci: test_source_prod Your tests passed on CircleCI!
Details
ci/circleci: test_source_prod_experimental Your tests passed on CircleCI!
Details
ci/codesandbox Building packages succeeded.
Details
@threepointone
Copy link
Contributor

@threepointone threepointone commented Feb 28, 2020

Looks good to me, thanks!

@henryqdineen henryqdineen deleted the henryqdineen:find-by-type-error-message branch Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.