我正在尝试测试 combineReducers 但出现以下错误。
TypeError: _testReducer.testReducer.test11 不是函数
以下是减速机
// 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,
});
以下是测试用例
// 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);
});
});
如果我在 reducer 中导出所有函数并在测试用例中导入单个函数,它会起作用,但这不是想法。