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 shallow: SFCs should not get this #13141

Closed
ljharb opened this issue Jul 3, 2018 · 2 comments
Closed

react-test-renderer shallow: SFCs should not get this #13141

ljharb opened this issue Jul 3, 2018 · 2 comments

Comments

@ljharb
Copy link
Contributor

ljharb commented Jul 3, 2018

Do you want to request a feature or report a bug?
bug.

What is the current behavior?
This addresses a bug in enzyme, enzymejs/enzyme#1683.

On this line element.type() invokes the SFC with element as the this value. I believe that this is needed for create-react-class components, but that there needs to be a separate branch for SFCs.

What is the expected behavior?
this inside a strict-mode SFC will be undefined, not the element.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
In all of React 0.13, 0.14, 15, and 16, this bug exists.

While the bug ideally will be fixed, I understand that it's highly unlikely that it would be backported to the 14/15 lines - but I can wrap around it if there's a reliable way, in those versions, to distinguish SFCs from create-react-class components (is there?).

@gaearon
Copy link
Collaborator

gaearon commented Jul 3, 2018

If something doesn't have .prototype or .prototype.isReactComponent, we won't try to new it.

(This still doesn't mean it's functional — it could return an object with a render method — but at least it shouldn't have this.)

Happy to take a fix for 16.x.

@ljharb
Copy link
Contributor Author

ljharb commented Jul 3, 2018

So both class and createReactClass components will have .isReactComponent on them? Is there a spec on providing a receiver to other things, or is my assumption correct that unless it’s newed, it should lack a receiver?

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

No branches or pull requests

2 participants