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

jest snapshot tests are failing with invariant Violation #163

Open
bseber opened this issue Feb 6, 2017 · 3 comments
Open

jest snapshot tests are failing with invariant Violation #163

bseber opened this issue Feb 6, 2017 · 3 comments

Comments

@bseber
Copy link

bseber commented Feb 6, 2017

recently I've replaced mocha with jest and I love the snapshot testing feature. Unfortunately this does not work for components using the react-list. The tests are failing with an invariant violation:

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 findDOMNode (node_modules/react-dom/lib/findDOMNode.js:49:41)
      at ReactList.getScrollParent (node_modules/react-list/react-list.js:191:18)
      at ReactList.updateScrollParent (node_modules/react-list/react-list.js:325:34)
      at ReactList.updateFrame (node_modules/react-list/react-list.js:310:14)
      at ReactList.componentDidMount (node_modules/react-list/react-list.js:149:14)
      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

Googling for this I found some react issues regarding react-test-renderer and react-dom imported by 3rd party libs. Now I am just mocking the react-list in the tests:

// __mocks__/react-list.js
import React from 'react';

const ref = () => {};

export default function ReactListMock ({
    items,
    itemsRenderer,
    itemRenderer,
}) {
    const itemElements = items.map ((item, index) => itemRenderer (index, index));
    return itemsRenderer (itemElements, ref);
}

Does anyone have another solution?
Or even know whats going wrong in react internals?

Shall we add this to the FAQ section in the readme?

@maullerz
Copy link

maullerz commented Feb 7, 2017

Just got similar error in rollbar


Invariant Violation: Minified React error #44; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=44 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
  File "webpack:///../~/react-dom/lib/reactProdInvariant.js", line 31, in n
      var error = new Error(message);
  File "webpack:///../~/react-dom/lib/findDOMNode.js", line 53, in r
        !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findDOMNode was called on ...
  File "webpack:///../~/react-list/react-list.js", line 218, in value
            var el = findDOMNode(this);
  File "webpack:///../~/react-list/react-list.js", line 352, in value
            this.scrollParent = this.getScrollParent();
  File "webpack:///../~/react-list/react-list.js", line 337, in value
            this.updateScrollParent();
  File "[native code]", line unknown, in value

the link contains

findDOMNode was called on an unmounted component.

@kachaj7
Copy link

kachaj7 commented Jul 17, 2017

I get similar error with jest.

TypeError: Cannot read property 'styleSheets' of undefined
      at Window.getComputedStyle (node_modules/jsdom/lib/jsdom/browser/Window.js:405:36)
      at ReactList.getScrollParent (node_modules/react-list/bin/react-list.js:170:24)
      at ReactList.updateScrollParent (node_modules/react-list/bin/react-list.js:301:32)
      at ReactList.updateFrame (node_modules/react-list/bin/react-list.js:286:12)
      at ReactList.componentDidMount (node_modules/react-list/bin/react-list.js:109:12)
      at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:264:25
      at measureLifeCyclePerf (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:75:12)
      at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:263: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)```

@bseber
Copy link
Author

bseber commented Jul 24, 2017

intentional beahviour by react-test-renderer

@see facebook/react#7371 (comment)

I will update the FAQ and do a pull request as soon as I can spare some time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants