Skip to content

jest snapshot tests are failing with invariant Violation #163

Open

Description

@bseber

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?

Activity

  1. maullerz commented on Feb 7, 2017

    @maullerz

    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.
    
  2. kachaj7 commented on Jul 17, 2017

    @kachaj7

    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)```
    
  3. bseber commented on Jul 24, 2017

    @bseber
    Author

    intentional beahviour by react-test-renderer

    @see react/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions