-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Unable to find node on an unmounted component #1411
Comments
First, However, I'm not sure why that would cause this issue. Does it work with react 15 and enzyme 3? |
@ljharb I was playing around with the implementation of I've tested with React 15 and and Enzyme 3.2 and the error is sligthly different:
Is this facebook/react#7371 probably the cause? |
In enzyme v3, shallow(<MyComponent />, {disableLifecycleMethods: true}); |
@expobrain yes, I think that is the cause. We may need to add functionality to the react adapters for 15+ to support https://reactjs.org/blog/2016/11/16/react-v15.4.0.html#mocking-refs-for-snapshot-testing. |
So far Enzyme 3 has been fine and I test a LOT. I use it in React 16 just fine. |
@expobrain but what if you wanted to test lifecycle method ? |
@dj-marko "when I do it I do it on production"(tm) :-) TBF on my test I din't had yet the need to test the lifecycle method yet, however when I'll need it I'll check again with the latest version of |
I'm running into this same issue with |
Updating |
Closing; happy to reopen if it's still reproducible on latest enzyme/adapters. |
I'm using shallow() to render my component in one of my tests, and unless I disable lifecycle callbacks I get the same error. Here is an excerpt of my code: componentDidMount() {
this.DOMElement = ReactDOM.findDOMNode(this) // <-- this breaks
this.scrollElement.addEventListener("scroll", lodash.throttle(() => {
this.hasScrolled();
}, 200))
} and my test: const component = shallow(<TipeeTopbar getConfig={getConfig} isModuleActive={isModuleActive} />)
expect(component).toMatchSnapshot() If I add |
I’d expect that, since you’d need a DOM available to find a DOM node. You’ll either have to use jsdom, or disable lifecycle methods for that test. |
I am using jsdom actually when running my tests, but unfortunately it doesn't change anything. |
Can you file a new issue, and include component code as well as the stack trace when it breaks? |
Sure! Here it is: #1835 |
With Enzyme 3.x and React 16 the following code stopped working:
Now the error is:
The text was updated successfully, but these errors were encountered: