0

I'm trying to solve out a basic jest example but i'm not able to mock the module. Inside the function B, i call A. I'd like to spy on A to make sure the call is made

helper.ts


    export function a(text: string): void {
      console.debug('A  : ', text);
    }
    
    export function b(text: string): void {
      a(text);
    }

helper.spec.ts


    import * as helpers from './test';
    
    jest.mock('./test', () => ({
      ...jest.requireActual('./test'),
      a: jest.fn(),
    }));
    
    describe('test', () => {
      it('not works', () => {
        helpers.b('test');
    
        expect(helpers.a).toHaveBeenCalled();
      });
    
      it('not works either', () => {
        const spy = jest.spyOn(helpers, 'a').mockImplementation();
    
        helpers.b('test');
    
        expect(spy).toHaveBeenCalled();
      });
    });

It seems that the mock is not made and I don't figure out why. The function a does not seem to be mocked despite the jest.mock or the spyOn

enter image description here

TLd
  • 424
  • 6
  • 18

0 Answers0