lundi 8 octobre 2018

How do I test a component method when using react-jss and enzyme?

I have basically this question:

https://github.com/airbnb/enzyme/issues/208

But my component is wrapped in the jss withStyles wrapper. I'm using the shallow method created by Material-UI as outlined here.

eg:

class Button extends React.Component {
  handleClick() {
    // Do something here
  }
  render() {
    // Component here
  }
}

const styles = {
     root: {}
}

export withStyles(styles)(Button); 

The problem is - wrapper.instance().handleClick() will throw handleClick() is not a function.

How do I access the component itself?

Aucun commentaire:

Enregistrer un commentaire