How to properly make mock throw an error in Jest?

前端 未结 2 716
悲哀的现实
悲哀的现实 2021-02-03 16:26

I\'m testing my GraphQL api using Jest.

I\'m using a separate test suit for each query/mutation

I have 2 tests (each one in a separate test suit) where I mock on

2条回答
  •  有刺的猬
    2021-02-03 17:11

    Change .mockReturnValue with .mockImplementation:

    yourMockInstance.mockImplementation(() => {
      throw new Error();
    });
    

提交回复
热议问题