-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
How to write tests regarding Action Creators which return functions? #700
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
Comments
The counter example app has some tests that cover this. it('incrementIfOdd should create increment action', () => {
const fn = actions.incrementIfOdd();
expect(fn).toBeA('function');
const dispatch = expect.createSpy();
const getState = () => ({ counter: 1 });
fn(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({ type: actions.INCREMENT_COUNTER });
}); Maybe an idea to add this to the documentation? |
@por |
Duplicate of #546.
I'd happily accept a pull request. |
I see it's not true anymore... Did the API change? I guess I should use https://github.com/gaearon/redux-thunk instead. |
Yes, use thunk if you want to have this. |
Also, there is a related issue: reduxjs/redux-thunk#14 |
It's mentioned in the documentation:
However, action creators can also return functions like this:
In this case, how do I write tests? It's not a simple checking object equality anymore.
Thank you
The text was updated successfully, but these errors were encountered: