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 Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.