Skip to content
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

[Tooltip] Invalid Value Calculated on Tooltip when Running Tests #5567

Closed
pvienneau opened this issue Nov 16, 2016 · 3 comments
Closed

[Tooltip] Invalid Value Calculated on Tooltip when Running Tests #5567

pvienneau opened this issue Nov 16, 2016 · 3 comments
Labels
component: tooltip This is the name of the generic UI component, not the React module!

Comments

@pvienneau
Copy link

Problem description

Tooltip component throws an invalid value error on the calculated left position when running in a test environment.

Seems that the offsetWidth is returned as undefined, which is being used to calculate the new value, which returned a calculated result of NaN. Not sure what is throwing this warning, but it can be addressed by setting a default value to the offsetWidth state to null.

Link to minimally-working code that reproduces the issue

See master...pvienneau:master for a code diff with a test that fails without the provided fix.

Versions

  • Material-UI: 0.16.2
  • React: 15.4.0
  • Browser: N/A
  • Node: 6.5.0
@Mythra
Copy link

Mythra commented Nov 28, 2016

I'm also running into this problem with jest (Same versions)

@joewalker
Copy link

The solution for me was here: https://facebook.github.io/react/blog/2016/11/16/react-v15.4.0.html#mocking-refs-for-snapshot-testing

describe('TestComponent', function(): void {
  const mocks = {
    tooltip: { offsetWidth: 100 },
    ripple: { style: {} },
  };
  function createNodeMock(element: Element<>): ?Object {
    return mocks[element.ref];
  }

  it('should render', function(): void {
    const muiTheme = getMuiTheme();
    const element = (
      <MuiThemeProvider muiTheme={muiTheme}>
        <TestComponent/>
      </MuiThemeProvider>,
    );

    const tree = renderer.create(element, { createNodeMock }).toJSON();
    expect(tree).toMatchSnapshot();
  });
});

@oliviertassinari
Copy link
Member

Closing for #2230

@oliviertassinari oliviertassinari added the component: tooltip This is the name of the generic UI component, not the React module! label Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tooltip This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

4 participants