Skip to content

Spying actions in unit tests #854

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

Closed
gpbl opened this issue Oct 6, 2015 · 2 comments
Closed

Spying actions in unit tests #854

gpbl opened this issue Oct 6, 2015 · 2 comments
Labels

Comments

@gpbl
Copy link

gpbl commented Oct 6, 2015

I have a test case where I'd like to count how many times an action is called. To do this, I'm using a spy:

import * as actions from "./actions"; // actions = { myAction: () => (/* etc */) }
import expect from "expect";

const spy = expect.spyOn(actions, "myAction");

doStuffDispatchingMyAction()
expect(spy.calls.length).toEqual(1); // throws!

Redux throws an error: Actions must be plain objects. Use custom middleware for async actions. Is this case related to this issue? How could I spy an action?

@gaearon
Copy link
Contributor

gaearon commented Oct 6, 2015

My guess is that you want expect.spyOn(...).andCallThrough().
Otherwise you're dispatching undefined.

@gpbl
Copy link
Author

gpbl commented Oct 7, 2015

Awesome thanks!

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

No branches or pull requests

2 participants