How to drown component methods that use property initializer syntax?

Finally, I upgrade my components from React.createClass()to ES6 classes. The first error that I see in my tests is that some of my calls sinon.stub()fail because I jscodeshift -t react-codemod/transforms/class.jsconverted my component methods to using a property initializer clause, i.e.

class Foo extends React.Component {
  componentWillMount() {
    this.fetchSomeData(this.props);
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.someProp !== this.props.someProp) {
      this.fetchSomeData(nextProps);
    }
  }
  fetchSomeData = (props) => {
    ...
  };
  render() {
    ...
  }
}

My question is: how can I drown fetchSomeData()with this new syntax? My tests look like sinon.stub(Foo.prototype, 'fetchSomeData');those that no longer work, assuming they are fetchSomeDatano longer in the prototype.

Thank!

+4
source share
1 answer

fetchSomeData() this, Foo.prototype, . , fetchSomeData() , . .

+3

Source: https://habr.com/ru/post/1674513/


All Articles