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

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

Closed
rhalff opened this issue Nov 17, 2016 · 5 comments
Closed

Comments

@rhalff
Copy link

rhalff commented Nov 17, 2016

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
@rhalff
Copy link
Author

rhalff commented Nov 17, 2016

Nevermind, just found it's not supported: #7371

@rhalff rhalff closed this as completed Nov 17, 2016
@gaearon
Copy link
Collaborator

gaearon commented Nov 17, 2016

Yea sorry, refs can work but findDOMNode() can't (we tried).

leebyron pushed a commit to graphql/graphiql that referenced this issue Dec 9, 2016
* Upgrade dependencies to fix build breakages

We've had some lint-related build failures:

  https://travis-ci.org/graphql/graphiql/builds/181453346

lately. Unfortunately, these masked test failures introduced by
35d8d38. When we fixed the lint (1eeb36c), the test failures showed
up:

  https://travis-ci.org/graphql/graphiql/builds/182431531

This commit fixes that by upgrading our deps:

- Replace "react-addons-test-utils", which access a path that doesn't
  exist in current "react-dom", with "react-test-renderer".

This required some API updates in the tests, but also some changes to
use ref-based DOM node access rather than `ReactDOM.findDOMNode`, which
doesn't work in "react-test-renderer".

See:

- facebook/react#7371
- facebook/react#8324

> Yea sorry, refs can work but `findDOMNode()` can't (we tried).

* Update package.json
@scrodrig
Copy link

I also have a problem....
When send a function in a prop to a child component... The production code works, however the test doesn't work same error. :(

@gaearon
Copy link
Collaborator

gaearon commented Jun 24, 2017

If you mean you're using findDOMNode() in test renderer, it won't work.
Please see #7371 for reasons why.

@byjoshuadavis
Copy link

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:

configure({
  adapter: new Adapter(),
  disableLifecycleMethods: true,
})

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

4 participants