Skip to content

Add note that shallowRenderer.createRenderrer can be used #2646

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JimLynchCodes
Copy link

Hello! I was following the docs here for Shallow rendering, and I was using it in a project with typescript. Doing "new ShallowRenderer()" would not even compile in typescript, and tbh I don't disagree with its "expression is not constructible" error message.

You can find more about the error I was having here: facebook/react#17726

I had worried my dear little self for a great deal of time until stumbling across a stack overflow question with an answer that shed a sparkling glimmer of hope on this mystery method: https://stackoverflow.com/questions/45047316/how-to-use-react-test-renderer-shallow-with-typescript/

The purpose of this PR is to add a small note on the ShallowRendering page letting the users of this ShallowRendering api know they can use ShallowRenderer.createRenderer(); if they receive errors about ShallowRender not being a constructible expression.

Also, just wanted to throw it out there that maybe the regular, recommended way should be calling the "createRenderer" function. What is the current reasoning for instructing the users to try to instantiate this object with the new keyword?

Thanks!

  • Jimbo

@facebook-github-bot
Copy link
Collaborator

Hi JimTheMan! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@reactjs-bot
Copy link

Deploy preview for reactjs ready!

Built with commit c1e2394

https://deploy-preview-2646--reactjs.netlify.com

@facebook-github-bot
Copy link
Collaborator

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

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.

3 participants