Reputation: 957
I have the following function I am trying to test with enzyme.
renderLoginLink(caption) {
return (
<a href="#" id="lnkAuthenticateWithGoogle" onClick={() => this.props.actions.authenticateWithGoogle()}>
{caption}
</a>
);
}
I'm using this to simulate the click.
let container, store
const mockStore = configureMockStore();
store = mockStore(initialState);
container = mount(<Provider store={store}><Login {...initialState} /></Provider>)
container.find("a#lnkAuthenticateWithGoogle").simulate("click")
I am getting an error that this.props.actions is undefined. I'm not sure what I am missing.
Upvotes: 4
Views: 936
Reputation: 281734
While mounting the component, you would need to provide the actions as props to it like
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")
Upvotes: 5