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

Menu and MenuItem thorw "Invariant Violation: getNodeFromInstance: Invalid argument" in snapshot test with jest #6971

Closed
dyesseyumba opened this issue May 27, 2017 · 2 comments
Labels
component: menu This is the name of the generic UI component, not the React module!

Comments

@dyesseyumba
Copy link

Problem description

I work with typescript, react and material-ui. I'm trying to do a snapshot test with jest. But material-ui's MenuItem throw Invariant Violation: getNodeFromInstance: Invalid argument. exception

Link to minimal working code that reproduces the issue

Here is the component I'm trying to test:

import * as React from 'react';
import {MuiThemeProvider, Paper, Menu, MenuItem, Divider} from 'material-ui';

class App extends React.Component < any,any > {

  public render() {
    return (
      <MuiThemeProvider>
        <div>
          <Paper >
            <Menu desktop={true}>
              <MenuItem primaryText="Back"/>
              <MenuItem primaryText="Forward" disabled={true}/>
              <Divider/>
              <MenuItem primaryText="Recently closed" disabled={true}/>
              <MenuItem primaryText="Google" disabled={true}/>
              <MenuItem primaryText="YouTube"/>
            </Menu>
          </Paper>
        </div>
      </MuiThemeProvider>
    );
  }
}

export {App};

Here is the test

import * as React from 'react';
import {App} from '../menu';
import * as renderer from 'react-test-renderer';

describe('Layout', () => {
  it('renders correctly', () => {

    const layout = renderer.create(<App />).toJSON();

    expect(layout).toMatchSnapshot();
  });
});

and the logs errors

Invariant Violation: getNodeFromInstance: Invalid argument.

      at invariant (node_modules/fbjs/lib/invariant.js:44:15)
      at Object.getNodeFromInstance (node_modules/react-dom/lib/ReactDOMComponentTree.js:162:77)
      at Object.findDOMNode (node_modules/react-dom/lib/findDOMNode.js:49:41)
      at ListItem.applyFocusState (node_modules/material-ui/List/ListItem.js:319:43)
      at MenuItem.applyFocusState (node_modules/material-ui/MenuItem/MenuItem.js:206:26)
      at MenuItem.componentDidMount (node_modules/material-ui/MenuItem/MenuItem.js:175:12)
      at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:265:25
      at measureLifeCyclePerf (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:75:12)
      at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:264:11
      at CallbackQueue.notifyAll (node_modules/react-test-renderer/lib/CallbackQueue.js:76:22)
      at ReactTestReconcileTransaction.close (node_modules/react-test-renderer/lib/ReactTestReconcileTransaction.js:36:26)
      at ReactTestReconcileTransaction.closeAll (node_modules/react-test-renderer/lib/Transaction.js:206:25)
      at ReactTestReconcileTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:153:16)
      at batchedMountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:69:27)
      at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:140:20)
      at Object.batchedUpdates (node_modules/react-test-renderer/lib/ReactDefaultBatchingStrategy.js:62:26)
      at Object.batchedUpdates (node_modules/react-test-renderer/lib/ReactUpdates.js:97:27)
      at Object.render (node_modules/react-test-renderer/lib/ReactTestMount.js:125:18)
      at Object.it (src/shell/containers/__tests__/app.test.tsx:8:29)
      at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
      at process._tickCallback (internal/process/next_tick.js:109:7

Versions

  • Material-UI: 0.18.1
  • React: 15.5.4
  • Browser: Chrome 58
  • Jest: 20.0.4
@oliviertassinari oliviertassinari added the component: menu This is the name of the generic UI component, not the React module! label May 27, 2017
@jeroenwienk
Copy link

facebook/react#7371 related? Since applyFocusState is called on a ref.

@oliviertassinari
Copy link
Member

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. While we haven't tested it, I think that the issue is most likely fixed on that branch. Hence, I'm closing it.
Still, we will accept PR fixes until v1-beta takes over the master branch.

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

No branches or pull requests

3 participants