Skip to content

[material-ui] Error in Tests [TypeError: Cannot read property 'scrollTop' of null] #17119

@Technologeek

Description

@Technologeek
  • [ x] The issue is present in the latest release.
  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

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.

const returnScrollable = () => {
  const [value, setValue] = useState(0);
  const handleChange = (event, newValue) => {
    setValue(newValue);
  };

  return (
    <>
      <Tabs
        tabItems={tabItemsScrollable} //array of tabs
        onChange={handleChange}
        value={value}
        variant="scrollable"
        scrollButtons="auto"
      />
    </>
  );
};

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]

The above error occurred in the <ScrollbarSize> component:
        in ScrollbarSize (created by ForwardRef(Tabs))
        in div (created by ForwardRef(Tabs))
        in ForwardRef(Tabs) (created by WithStyles(ForwardRef(Tabs)))
        in WithStyles(ForwardRef(Tabs)) (created by SBTabs)
        in header (created by ForwardRef(Paper))
        in ForwardRef(Paper) (created by WithStyles(ForwardRef(Paper)))
        in WithStyles(ForwardRef(Paper)) (created by ForwardRef(AppBar))
        in ForwardRef(AppBar) (created by WithStyles(ForwardRef(AppBar)))
        in WithStyles(ForwardRef(AppBar)) (created by SBTabs)
        in div (created by SBTabs)
        in SBTabs (created by WithStyles(SBTabs))
        in WithStyles(SBTabs) (created by BaseStoryScrollable)
        in BaseStoryScrollable

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:

  1. Create a component using Tabs and try Jest snap-shot testing it.

Context 🔦

Your Environment 🌎

Tech Version
Material-UI v4.3.1
React 16.9.0
Browser Chrome
TypeScript NA
etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to the documentationtest

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions