makeomatic / makeomatic/redux-connect
asyncConnect promises are not called when running jest test
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 545
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
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(, {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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Component.js and component.spec.js, then reproduce the behavior using the shown Jest shallow render and asyncConnect promise. Trace whether the promise is invoked and whether loadDetails reaches the mocked store dispatch; done means the test observes the expected action dispatch or clearly documents the supported test setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100