Haris Khan Haris Khan - 2 months ago 51
React JSX Question

spyOn a function not working - jasmine

import * as PlanReducer from '../../../reducers/planReducer';

describe('currentPlanReducer()', () => {

beforeAll(() => {

spyOn(PlanReducer, 'planReducer').and.callThrough();


PlanRedcuer is :

export default function planReducer(state = INITIAL_STATE, action) {....}

It throws me an error during test that planRedcuer is not a method, I tried to import other method like that (which was not export default) and it worked. Can any one help me with how I can spy on the function and test it?


You're not exporting the planReducer function as planReducer, but as default. Therefore, in the test you should spy on the default property:

spyOn(PlanReducer, 'default').and.callThrough();

Alternatively, you can export the planReducer as both default and planReducer:

const planReducer = function planReducer(state = INITIAL_STATE, action) {...}
export {planReducer}
export default planReducer