-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
find(MyStatelessFunctionalComponent) fails when running on minified react-dom #1041
Comments
The minified version of react-dom is for production; enzyme is for testing; testing is not done in production. Certainly it's undesirable, but this level of coupling is unavoidable when React does not expose the things we need to make enzyme work ¯\_(ツ)_/¯ I'm assuming this is failing because the minified react-dom is mangling function names; at that point there's likely nothing in that particular function that can identify it such that we can determine if it's a functional component. I'll leave this open in case we can find a way, but the real solution is to use the unminified version of react and react-dom when running tests. |
As for testing not being done in production, not sure I agree. IMO testing should be done on dev builds and production builds, otherwise how can you be sure your production build isn't fudged, and I'd generally argue you want to run all tests against the thing you actually ship. Tests shouldn't be tied to the codebase being unminified. Anyway, you're right, it fails because the function name is mangled in the minification, and I think it's a difficult issue; I don't know how you'd tests for something being a stateless component other in the way you've done it above, I'll keep thinking |
Thanks - if we can fix this so it works with the minified build, that'd obviously be an improvement :-) |
I don't think we need |
Yes but |
|
Ah, fair enough - sounds like this is resolved by #1007 then (people still shouldn't be mangling function names ever, tho) |
I think we need to make a small change to use the |
I reviewed Query Selector fails common issues and I don't think this is covered there.
If I make a stateless functional component e.g.
const MyStatelessFunctionalComponent = (props) => <input {...props}/>;
I can then mount it with enzyme and query to find it within my wrapper e.g.
And then query my wrapper to grab that component
wrapper.find(MyStatelessFunctionalComponent)
This all works fine when I'm not using a minified version of react-dom. But, as soon as I use a minifed version of react-dom it fails -> i.e. the find retrieves no nodes 😱
I think the problem is this pieve of code from Utils.js
in particular
functionName(inst.constructor) === 'StatelessComponent';
This seems extremely highly coupled to react-dom, and in particular the fact that they have a function called StatelessComponent. Thus as soon as you run against a minified version it fails.
I would argue that being so highly coupled to the internal implementation of react-dom is undesirable and leads to unnecessary fragility.
The text was updated successfully, but these errors were encountered: