我有以下功能,我试图用酶来测试。
renderLoginLink(caption) {
return (
<a href="#" id="lnkAuthenticateWithGoogle" onClick={() => this.props.actions.authenticateWithGoogle()}>
{caption}
</a>
);
}我用这个来模拟点击。
let container, store
const mockStore = configureMockStore();
store = mockStore(initialState);
container = mount(<Provider store={store}><Login {...initialState} /></Provider>)
container.find("a#lnkAuthenticateWithGoogle").simulate("click")我收到一个错误,this.props.actions是未定义的。我不知道我错过了什么。
发布于 2018-10-02 17:07:34
在挂载组件时,您需要将这些操作提供给它,如
let container, store
const mockStore = configureMockStore();
store = mockStore(initialState);
const actions = {
authenticateWithGoogle: jest.fn()
}
container = mount(<Provider store={store}><Login {...initialState} actions={actions}/></Provider>)
container.find("a#lnkAuthenticateWithGoogle").simulate("click")https://stackoverflow.com/questions/52612845
复制相似问题