ReactTestRenderer: Invariant Violation: getNodeFromInstance: Invalid argument.
See original GitHub issueI’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
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Invariant Violation: getNodeFromInstance: Invalid argument ...
I run into a bug within react-test-renderer, Invariant Violation: getNodeFromInstance: Invalid argument. Minimal code to replicate the bug:
Read more >Invariant Violation - Invalid argument-Reactjs - appsloveworld
Coding example for the question ReactTestRenderer: Invariant Violation: getNodeFromInstance: Invalid argument-Reactjs.
Read more >mozilla-central: changeset 479280 ...
err.name = 'Invariant Violation'; - throw err; - } + invariant$2(typeof ... var getInstanceFromNode = null; var getNodeFromInstance = null; ...
Read more >React Native Test Error - Unable To Find Node On ... - ADocLib
I've tested with React 15 and and Enzyme 3.2 and the error is sligthly different: Invariant Violation: getNodeFromInstance: Invalid argument. Is this.
Read more >orgsync - Bountysource
Invariant Violation: getNodeFromInstance: Invalid argument. at invariant ... at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:265:25 at ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nevermind, just found it’s not supported: https://github.com/facebook/react/issues/7371
I came upon this issue after upgrading from Enzyme 2 to Enzyme 3. If anyone experiences this when upgrading Enzyme, it can be fixed by disabling testing of the lifecycle methods: