我终于将我的组件更新React.createClass()为ES6类.我在测试中看到的第一个错误是我的一些sinon.stub()调用失败,因为jscodeshift -t react-codemod/transforms/class.js转换了我的组件方法以使用属性初始化程序提议,即
class Foo extends React.Component {
componentWillMount() {
this.fetchSomeData(this.props);
}
componentWillReceiveProps(nextProps) {
if (nextProps.someProp !== this.props.someProp) {
this.fetchSomeData(nextProps);
}
}
fetchSomeData = (props) => {
...
};
render() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何fetchSomeData()使用这种新语法存根?我的测试看起来sinon.stub(Foo.prototype, 'fetchSomeData');不再适用,假设因为不再fetchSomeData是原型.
谢谢!