Skip to content

Invariant Violation error thrown when testing on Stateful Component #284

@qingweibinary

Description

@qingweibinary

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(...)

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