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!
source
share