-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[material-ui] Error in Tests [TypeError: Cannot read property 'scrollTop' of null] #17119
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
Comments
@Technologeek Thanks for opening this issue, this is related to #17070 and how we should improve our testing guide. I think that it's a topic we have already discussed in #16523. The solution we went for is to test all our components with: import ReactTestRenderer from 'react-test-renderer';
ReactTestRenderer.act(() => {
ReactTestRenderer.create(<Foo />, {
createNodeMock: node => {
return document.createElement(node.type);
},
});
}); +80% of our components are passing this test. We will work on raising it to 100%. The ones that don't are the components using react-transition-groups or mounting a Portal. It's not the case of the tabs. I assume that you are using Looking at the sources, it leads me to: https://github.com/storybookjs/storybook/blob/v5.2.0-beta.39/addons/storyshots/storyshots-core/src/frameworks/react/renderTree.js. Alright, it seems that part of the solution is documented in: https://github.com/storybookjs/storybook/tree/master/addons/storyshots/storyshots-core#using-createnodemock-to-mock-refs. Could you try the following? import ReactTestRenderer from 'react-test-renderer';
import initStoryshots, { snapshotWithOptions } from '@storybook/addon-storyshots';
initStoryshots({
test: snapshotWithOptions({
renderer: storyElement =>
ReactTestRenderer.act(() => {
ReactTestRenderer.create(storyElement, {
createNodeMock: node => document.createElement(node.type),
});
}),
}),
}); or import initStoryshots, { snapshotWithOptions } from '@storybook/addon-storyshots'
initStoryshots({
test: snapshotWithOptions({
createNodeMock: node => document.createElement(node.type),
}),
}) |
@oliviertassinari Thanks a lot for your quick reply! As far as my use-case is concerned, I'm not getting any console-errors or warnings and the component seems to pass all other tests. I could apply your suggestion but it is not needed at the moment. We have multiple such third party elements which fail tests due to ForwardRefs but the component works great without any console errors. For now, I prefer to just ignore that story. If it helps anybody, this is how you ignore a story.. //In your storyshots.test.js file import initStoryshots from "@storybook/addon-storyshots";
initStoryshots({
storyKindRegex: /^((?!.*?NameOfYourStory).)*$/
}); Thanks again for your help! |
Hey @oliviertassinari just wanted to say that the solution you provided with Thanks 🙏 |
@carloscuesta Thanks for the feedback! Now, we need to update the testing guide: #17070. Any help would be appreciated. |
This comment has been minimized.
This comment has been minimized.
If you use this theme you need to make sure that children of transition components forward their refs to the outermost DOM node. The original plan was to add documentation for this but there were other StrictMode issues that weren't fixable so I didn't pursue this beyond internal usage. Would greatly appreciate it if someone would add docs for
|
thanks for this explanation, now I know how to fix this I'm using it only in Dev to test how it goes |
This works fine for me. Thank you! |
I'm not really sure I understand what the internal problem is, but the code above didn't work for me. It's crashing on the
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@siriwatknp This issue is about the lack of ref in the test environment (react-test-renderer). I think that the issue you are talking about is related but different. I'm not sure we should discuss it here. Maybe it should happen in a new issue with a reproduction? |
Okay, will create a new issue with reproduction: #27154. |
For me, issue occurs even in browser. It's very rare so I'm not able to reproduce. Probably happens after the
https://sentry.io/share/issue/8026280039644d4f9a4784928818290f/ Could we check that |
Yes, I could detect it too on Sentry. It happens on Chrome Browser at least:
I suspect the Tabs component too. |
Feel free to submit a PR. |
Observed. ☝️
WORKAROUNDset
|
Due to multiple issues that occur on the MUI transition in this instance, the grow transition is disabled. This isn't the optimal solution, further investigation is needed. Attempted to apply the solutions mentioned on bug reports. Added a React.Fragment wrap, which resolved only some of the issues. Specifically the "Uncaught TypeError: Cannot read properties of null (reading 'scrollTop'). Might be missing something small. See mui/material-ui#27154 mui/material-ui#18119 mui/material-ui#17119
Due to multiple issues that occur on the MUI transition in this instance, the grow transition is disabled. This isn't the optimal solution, further investigation is needed. Attempted to apply the solutions mentioned on bug reports. Added a React.Fragment wrap, which resolved only some of the issues. Specifically the "Uncaught TypeError: Cannot read properties of null (reading 'scrollTop'). Might be missing something small. See mui/material-ui#27154 mui/material-ui#18119 mui/material-ui#17119
With the switch to the Intersection Observer API for handling scroll button visibility since |
Closing this as completed since the error should no longer occur 😅 but we can always reopen it if new reports come in. |
Current Behavior 😯
Hi, I'm using the Tabs component and passing all the props that I require using my own wrapper component. Everything is working fine except when I add scrollable prop to the component.
This works as it's supposed to be without any errors on the console but when I run tests through Jest of updating the snap-shots using storybook, I'm getting an error.
Error: Uncaught [TypeError: Cannot read property 'offsetHeight' of null]
Error: Uncaught [TypeError: Cannot read property 'scrollTop' of null]
Expected Behavior 🤔
The tests should pass just like it does when the scrollable prop is not passed on the Tabs component.
Steps to Reproduce 🕹
Steps:
Context 🔦
Your Environment 🌎
The text was updated successfully, but these errors were encountered: