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

UnhandledPromiseRejectionWarning: Unhandled promise rejection: TypeError: dispatch is not a function #88

Closed
greygatch opened this issue Jan 30, 2017 · 2 comments

Comments

@greygatch
Copy link

greygatch commented Jan 30, 2017

My mocha tests are passing, but I am getting this new error about how 'dispatch' is not a function.

import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
const mockStore = configureMockStore([thunk]);

it('should attempt to login', (done) => {
    const userInfo = {email: 'Fizz', password: 'Buzz'};
    const userActions = require('../../../src/actions/userActions');
    const store = mockStore({});
    const dispatch = store.dispatch;
    const login = userActions.login;

    store.subscribe(() => {
        expect(store.getActions()[0].type).to.equal('LOG_IN');
        expect(store.getActions()[0].data.email).to.equal('Fizz');
        expect(store.getActions()[0].data.password).to.equal('Buzz');
        done();
    });

    dispatch(userActions.asyncLogin(userInfo)(dispatch(login(userInfo))));
});
@greygatch
Copy link
Author

This is my dispatch variable:

function (action) {
  return typeof action === 'function' ? action(dispatch, getState) : next(action);
}

@arnaudbenard
Copy link
Contributor

It looks like a JS error, you need to call store.dispatch or define dispatch as

const dispatch = store.dispatch.bind(store);

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

2 participants