import * as PlanReducer from '../../../reducers/planReducer';
describe('currentPlanReducer()', () => {
beforeAll(() => {
spyOn(PlanReducer, 'planReducer').and.callThrough();
});
});
PlanRedcuer 是:
export default function planReducer(state = INITIAL_STATE, action) {....}
它在测试过程中向我抛出一个错误,即 planRedcuer 不是一种方法,我尝试导入其他类似的方法(不是导出默认值)并且它有效。任何人都可以帮助我了解如何监视该功能并测试它吗?
最佳答案
您不会将 planReducer
函数导出为 planReducer
,而是导出为 default
。因此,在测试中您应该监视 default
属性:
spyOn(PlanReducer, 'default').and.callThrough();
<小时/>
或者,您可以将 planReducer
导出为 default
和 planReducer
:
const planReducer = function planReducer(state = INITIAL_STATE, action) {...}
export {planReducer}
export default planReducer
关于javascript - spy 功能不起作用 - Jasmine ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281916/