redux-connect
redux-connect copied to clipboard
asyncConnect promises are not called when running jest test
I am writing test cases for one of my connected component that has asyncConnect in them.
Component.js
export default asyncConnect([
{
promise: ({
location: { query },
store: { dispatch },
}) => {
if (query.ids && query.ids.length) {
return dispatch(loadDetails(query.ids));
}
// return some promise.
}
}
],
state => ({
details: state.details
}),
dispatch => ({
// some dispatch
})
)
Below is my Jest test case component.spec.js
const create = () => {
const initialState = {};
const store = {
getState: jest.fn(() => initialState),
dispatch: jest.fn(),
subscribe: jest.fn()
};
const next = jest.fn();
return {store, next};
};
describe('Component async test', () => {
const props = {
// props initialization
};
const { store } = create()
const context = { store }
const sComponent = shallow(<Component {...props} />, {context});
it('renders correctly', () => {
expect(sComponent).toMatchSnapshot();
});
});
When i check the code coverage I found my loadDetail action is not dispatch. even the promise function is not called. What should I do to call my loadDetail action on shallow render.