-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Jest Snapshots fail with ScrollablePane with error TypeError: Cannot read property '__events__' of null #6681
Comments
The problem is that The better fix here is to look at why target is null. In this case, I see that
So my guess is that 1. your test is actually mounting the component, calling this code, and that |
I got it reproing, and So that's weird. Why would the ref be null? Debugging more. |
ref is not supported by react-test-renderer. Can you use enzyme? |
Ah ha, here's the workaround:
https://reactjs.org/docs/test-renderer.html#ideas It would be better to just use this in your test to allow react-test-renderer to create refs. The exception is occurring because the code assumes after mount the refs have been resolved, which is totally reasonable. |
I'm a little late to reply here, but i cannot thank you enough for all the help for this issue! This will definitely be the way to go for our unit tests! Thanks again! |
Please provide a reproduction of the bug in a codepen:
We would have to expose some of our components here, which i am unfortunately not getting the ok to. I'll see if i can get a reproduction using a mock ScrollablePane soon.
Please see my description of the issue, as i see a way to fix it, so i can just get a pr up for that if need be.
Bug Report
Priorities and help requested:
Are you willing to submit a PR to fix? (Yes, No) : If the fix is as simple as i mention i can get a pr up shortly.
Requested priority: (Blocking, High, Normal, Low): Normal (we're commenting out those jest tests for now)
Products/sites affected: (if applicable): N/A
Describe the issue:
This issue is only happening with a ScrollablePane that is rendered using react-test-renderer. When doing a test there, we are getting a TypeError in EventGroup.js line 136, with an error message of
The line number above corresponds to line 209 in the typescript version of that file.
I've tested a fix locally, but was a little hesitant to open a pr due to possible side effect issues that i might not be aware of. The fix is to simply check if the target is null before trying to access the events object. When making that fix it does remove that typeerror, and our unit tests then pass. If that does sound like a good idea i can go ahead and get a PR up shortly, but i figured i'd open an issue before doing that.
Actual behavior:
It is crashing before the test can be completed.
Expected behavior:
When running a unit test in jest through react-test-renderer that uses a ScrollablePane, the test will pass successfully.
The text was updated successfully, but these errors were encountered: