Chen Jian's Java Blog 

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

by Chen Jian

Posted on 2019-07-25 13:58 in Frontend

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

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

    //reference the mocked function

No one has commented yet.