I am trying to test combineReducers but getting following error.
TypeError: _testReducer.testReducer.test11 is not a function
Following is the reducer
// testReducer.js
import { combineReducers } from "redux-immutable";
const test11 = (state, action) => {
switch (action.type) {
case "temp11":
return true;
default:
return state;
}
};
const test22 = (state, action) => {
switch (action.type) {
case "temp22":
return false;
default:
return state;
}
};
export const testReducer = combineReducers({
test11,
test22,
});
Following is the test case
// testReducer.test.js
import { testReducer } from "./testReducer.js";
describe("test for testReducer", () => {
it("test11", () => {
const returnTrueValue = true;
expect(
testReducer.test11(
true, {
type: "temp11",
}
)
).toEqual(returnTrueValue);
});
it("test11", () => {
const returnFalseValue = false;
expect(
testReducer.test22(
true, {
type: "temp22",
}
)
).toEqual(returnFalseValue);
});
});
It worked if I export all functions in reducer and import individual in test case but thats not the idea case.
combineReducers returns a function that merges the states of all the reducers you put in it. It does not allow you to access individual reducers and call them individually.
You should use it this way for your case:
expect(
testReducer(true, {type: "temp11"}).test11
).toEqual(returnTrueValue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With