Actions without types throw an error rather than return the default state
See original GitHub issueIn my test setup code I have this line:
test.beforeEach(t => {
const initialState = reducer();
});
where
const reducer = handleActions({ ... }, { /*initial state*/});
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!
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
useReducer's initialState is typed as never? - Stack Overflow
I will attempt crudely to illustrate below. Error: passing default value as IObject here ↓ const reducer = (state: IObjectState, action: ...
Read more >Error, IfError, IsError, and IsBlankOrError functions in Power ...
Reference information including syntax and examples for the Error, IfError, IsError, IsBlankOrError functions in Power Apps.
Read more >Control flow and error handling - JavaScript - MDN Web Docs
Exception types Just about any object can be thrown in JavaScript. Nevertheless, not all thrown objects are created equal. While it is...
Read more >10 Handling PL/SQL Errors
A SELECT INTO statement returns no rows, or your program references a deleted element in a nested table or an uninitialized element in...
Read more >createReducer - Redux Toolkit
defaultCaseReducer A "default case" reducer that is executed if no case reducer and no matcher reducer was executed for this action. Returns.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the duplication/noise, and 🙏 for a great project! I thought I’d searched the issues properly but I guess not.
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.