I am trying to run a unit test using Jest in React, on my componentDidMount()
method, and only that method. my componentDidMount()
is as follows:
componentDidMount() {
//Delay to simulate welcome loading screen
const delay = 2000;
setTimeout(() => {
this.setState({ appLoaded: true }); //this line has no coverage, according to IDE
}, delay);
}
I tried to follow this and I got a bunch of errors. One of the big differences is that the sample given has a componentDidMount()
method that is nothing like mine. My componentDidMount()
has a local function in it, theirs doesn't. How can I unit test this?
also, in particular, I want to test the line that says this.setState({ appLoaded: true });
as it's the line that's said to not be covered.