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
    expect(mockedModule.someFunction.mock.calls.length).toBe(1);
 
});



No one has commented yet.
该日志评论功能被禁用了。