I'm facing an issue with my reducer in Redux where it is supposed to only accept numerical values, but when I test it with non-numeric input, the state still gets updated. Why is my reducer not filtering out non-numerical inputs?
Here is how my action is defined:
setCount: (count: number) => createAction(ActionTypes.SET_COUNT, {count})
This snippet shows the relevant code from my reducer:
case ActionTypes.SET_COUNT: {
draft.count = action.payload.count;
break;
}
And here is the unit test that I wrote:
describe(`(Action) ${ActionTypes.SET_COUNT}`, () => {
const unsuccessfulAction = Actions.setCount("bad input");
it("Should not update the state for the count when input is not a number", () => {
const state = myReducer(undefined, unsuccessfulAction);
expect(state.count).toBe(null);
});
});
Upon running the test case, I received "bad input" as the result while expecting null.