Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncConnect promises are not called when running jest test #126

Open
rahuljain-tt opened this issue Apr 26, 2018 · 0 comments
Open

asyncConnect promises are not called when running jest test #126

rahuljain-tt opened this issue Apr 26, 2018 · 0 comments

Comments

@rahuljain-tt
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant