-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fix TypeError: Cannot read property 'className' of undefined
#38
Conversation
In some weird corner cases, the following error is thrown: `TypeError: Cannot read property 'className' of undefined`.
@@ -4,6 +4,7 @@ dist | |||
.opt-in | |||
.opt-out | |||
.DS_Store | |||
.eslintcache |
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.
Sorry for the noise, but it was missing in the .gitignore file 😄.
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.
Sounds good 👍
Looks like we need a test for this. Could you add one? |
Codecov Report
@@ Coverage Diff @@
## master #38 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 4 4
Lines 158 159 +1
Branches 41 42 +1
=====================================
+ Hits 158 159 +1
Continue to review full report at Codecov.
|
@kentcdodds Thanks a lot for the quick feedback 🚀🎉. I've added a small test case for that weird corner case. |
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.
Super-duper. Thanks!
@kentcdodds Thanks a ton ❤️! |
We are using jest-glamor-react in production in our company and so far, this is a super piece of code. Thanks for your awesome work 👍!
What:
I've recently (first time ever) faced a weird issue in some of our (non open-sourced) components:
The error is thrown only because of the snapshot creation. Removing the
expect(wrapper).toMatchSnapshot()
line fixes it (but this obviously not what we want).We are using Enzyme and all the other tests are passing (i.e. nothing is broken). The issue was triggered after splitting one component in smaller chunks.
Why:
For some reason, the
props
are undefined in thegetSelectorsFromProps
method (utils). Consequently, an error is thrown in https://github.com/kentcdodds/jest-glamor-react/blob/master/src/utils.js#L37-L38 when trying to access theclassName
property of theprops
object.How:
The changes involved are quite simple, returning an empty array early actually solves it. The unit tests of the repository are passing and our tests are not altered at all (a good sign!).