Skip to content

ReactTestRenderer: Invariant Violation: getNodeFromInstance: Invalid argument. #8324

Closed
@rhalff

Description

@rhalff

I'm following the example at https://facebook.github.io/jest/docs/tutorial-react.html#content in order to use snapshots with jest.

I run into a bug within react-test-renderer, it seems to fail whenever findDOMNode is used on a component instance.

Minimal code to replicate the bug:

import React, { Component } from 'react'
import { findDOMNode } from 'react-dom'
import renderer from 'react-test-renderer'

class MyComp extends Component {
  componentDidMount() {
    findDOMNode(this)
  }
  render() {
    return <i />
  }
}

renderer.create(<MyComp />);

The Error:

 Invariant Violation: getNodeFromInstance: Invalid argument.
      
      at invariant (node_modules/fbjs/lib/invariant.js:38:15)
      at Object.getNodeFromInstance (node_modules/react-dom/lib/ReactDOMComponentTree.js:155:77)
      at findDOMNode (node_modules/react-dom/lib/findDOMNode.js:49:41)
      at MyComp.componentDidMount (my.test.js:7:59)
      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.<anonymous> (my.test.js:14:55)
      at process._tickCallback (internal/process/next_tick.js:103:7)

React versions:

  • react: 15.4.0
  • react-dom: 15.4.0
  • react-test-renderer: 15.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions