makeomatic / makeomatic/redux-connect

asyncConnect promises are not called when running jest test

Open
#126 0 comments 1 reaction 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.