8000 Invariant Violation error thrown when testing on Stateful Component · Issue #284 · enzymejs/enzyme · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Invariant Violation error thrown when testing on Stateful Component #284

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

Closed
qingweibinary opened this issue Mar 28, 2016 · 2 comments
Closed

Comments

@qingweibinary
Copy link

I am using React 15.

I have a component which call setTimeout in componentWillMount, the function is similar to

class Test extends Component {
    componentWillMount() {
        this.timer = setTimeout(() => this.setState(....), 4000);
    }
    // .....
}

When the timer is triggered, an error is thrown as follow

Invariant Violation: React DOM tree root should always have a node reference.

Here's a related issue on React
facebook/react#6232

Is there anyway I could prevent throwing error when testing, without using JSDOM?

Edit1:
this.setState(...) to () => this.setState(...)

@imontiel
Copy link
imontiel commented Dec 5, 2016

Do you have a componentWillUnmount that clears the timer?

You will have to run wrapper.unmount() after your tests to make sure that the componentWillUnmount gets called.

@ljharb
Copy link
Member
ljharb commented Jul 6, 2018

You generally don't want to call setState inside componentWillMount.

@ljharb ljharb closed this as completed Jul 6, 2018
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

3 participants
0