我在单独的操作目录中执行的操作之一:
export const updateScore = (vals) => {
return {
type: "UPDATE_VALS",
payload: {
numbers: vals.numbers,
score: vals.score
}
}
}
我的matchDispatchToProps
功能:
function matchDispatchToProps(dispatch) {
return {
actions: {
updateScore: bindActionCreators(updateScore, dispatch),
showSplash: bindActionCreators(showSplash, dispatch),
updateValue: bindActionCreators(updateValue, dispatch)
}
}
}
如何调用:
updateVals() {
this.props.actions.updateScore({
numbers: {
x: randomNumber(),
y: randomNumber()
},
score: this.props.arithmetic.score+1
});
}
如何在Jest中使用:
beforeEach(() => {
wrapper = shallow(<Arithmetic />);
});
对于大块代码感到抱歉,但我觉得我必须包含所有内容。虽然我在Cannot read property 'updateScore' of undefined
中测试的文件底部定义了我的操作,但我收到错误matchDispatchToProps
。我想知道我是否需要在Jest测试中添加额外的东西?我尝试用花括号导入测试:
import { Arithmetic } from "./Arithmetic";
并且还导出主要的未连接组件。苦苦寻找我在这里错过的东西。
请注意,当我启动服务器时,这种方法很好,但在我的测试中似乎失败了。