-
Notifications
You must be signed in to change notification settings - Fork 297
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
Actions without types throw an error rather than return the default state #140
Comments
A reducer returns the default state when the state given is undefined; the action must exist. This isn't FSA thing, just a Redux thing. Your test is throwing an expected error because you haven't given it an action; reducers respond to actions. For tests around this, see
For background material, see |
Thanks @yangmillstheory - the background material helps. Follow-up question: I actually originally tried |
See #139 (comment) and the comment below it. |
Sorry for the duplication/noise, and 🙏 for a great project! I thought I'd searched the issues properly but I guess not. |
Out of curiosity, when do you encounter actions in your app that don't have a If you're using this library, |
Yeah at this point it's just 🚴🏚-ing about test setup code, I can't imagine a real example of having an undefined action or action type being dispatched. And I think I understand the argument that having the "robustness" to handle that is more bad than good. |
In my test setup code I have this line:
where
However, the first method throws an error because:

and in the transpiled source it looks like
action.type.toString()
is called unguardedly. Now, maybe I'm misunderstanding how FSAs work, but I think it makes sense for a reducer test to be able to check that the initial state is returned when the action type is missing. I can try to make a PR for this as well, if you think I'm correct about the expected behaviour.If not, could you please fill me in on what I'm missing? Thanks!
The text was updated successfully, but these errors were encountered: