Jest mocking TypeScript class “No overload expects 1 type arguments”

前端 未结 3 770
执笔经年
执笔经年 2020-12-18 11:45

I\'m trying to mock a TypeScript class with Jest and I\'m obviously doing something because receive the following error:

error TS2743: No overload expects 1          


        
3条回答
  •  时光取名叫无心
    2020-12-18 12:13

    Jest has the following signature for jest.fn:

    /**
     * Creates a mock function. Optionally takes a mock implementation.
     */
    function fn(implementation?: (...args: Y) => T): Mock;
    

    So you need to specify the array of types for the args, in your particular case you could just pass an empty array as there are no args in your implementation function.

    const MockFoo = jest.fn(() => ({
    

提交回复
热议问题