In typescript: use Jest mock a function from a module, and reference this mocked function


import * as someModule from "../SomeModule";



test("xxx", ()=>{
    const mockedModule = someModule as jest.Mocked < typeof someModule  >  ;
    mockedModule.someFunction = jest.fn(); 

    ...
    //reference the mocked function
    expect(mockedModule.someFunction.mock.calls.length).toBe(1);
 
});

Leave a Reply

Your email address will not be published. Required fields are marked *