-
-
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
hasClassName throws Error if component has property className which is not a string #453
Conversation
…tring on custom components
fdcd2d5
to
f52830a
Compare
@@ -27,6 +27,9 @@ export function childrenOfNode(node) { | |||
|
|||
export function hasClassName(node, className) { | |||
let classes = propsOfNode(node).className || ''; | |||
if (node && typeof node.type === 'function' && typeof classes !== 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do the typeof
check instead of all these checks on node
? No matter what, if classes
is not a string we should exit early since the next operation is a string operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have the overview of the whole codebase, but I would consider it good if the method throws if its a native component and className
is not a string. That should not be a silent error?
So;
node && typeof node.type === 'function'
if that is true the node currently being processed is a custom component. If its not a custom component e.g a regular div, span etc, it will continue and have the same behavior as today, that is throw a error if you have passed something else then a string to className
.
That's my take on it. What do you think? Your decision, of course :)
Updated the PR according to your comments. Didn't update the code inside |
Well... We're not using the mounted version of enzyme that much yet. But from looking at the code in MountedTraversal.js and the patch in #448 they both address issues around the class checking. The #448 patch just adds support for checking the The problem described in this issue (#453) doesn't exist in the mounted part of the code because in MountedTraversal.js a check for The only "conflict" I see is that the patch in #448 should maybe be applied to the ShallowTraversal.js also, or at least ported. So that the behavior is consistent. Then both methods that check for classnames has the following behavior:
|
@aweary Are you interested in getting this in, or should I close the issue? |
@aweary what do you think we should do with this PR? |
I don't think we should throw if it's not a string, using an object with an overloaded We should probably just coerce |
This looks worthwhile to get in in some form - either way it needs to be rebased, now that #448 is already merged. |
@ljharb looks like we posted at the same time, ping just in case you missed my comment 🙂 |
Coercing to string (with |
@trmjoa do you want to update your PR to just coerce |
I will rebase and update the PR over the weekend. |
The linked issue was closed with 3070850 |
A proposal to fix #452
I now see that there are PR's pending for related issues (#448). I'm not sure if the proposed fixes/code changes are overlapping.
If you feel its a viable approach, but want changes, please advise me on how to proceed and I will give it a try.