Sign in
Log inSign up

setState in componentDidMount, enzyme tests failing

Manohar Srinivasa's photo
Manohar Srinivasa
·Sep 5, 2018

my cDM looks like the following

cDM() {
  //check if browser supports a feature
 //if yes then setState to denote it is supported
 this.setState( { supports: true });
}

render() {
 if(this.state.supports) // show button;
else // show "not supported" message
}

The "this.setState" call in cDM is making the enzyme "mount" to fail. Any ideas how to fix this? Or is there another way i can achieve it (instead of using state )

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct