Mock dependency in jest with typescript

前端 未结 9 1079
梦谈多话
梦谈多话 2020-12-07 12:03

When testing a module that has a dependency in a different file. When assigning that module to be jest.Mock typescript gives an error that the method mock

9条回答
  •  难免孤独
    2020-12-07 12:36

    Cast as jest.Mock

    Simply casting the function to jest.Mock should do the trick:

    (dep.default as jest.Mock).mockReturnValueOnce('return')
    
    

提交回复
热议问题