How to test the type of a thrown exception in Jest

后端 未结 12 1216
误落风尘
误落风尘 2020-12-04 18:37

I\'m working with some code where I need to test the type of an exception thrown by a function (is it TypeError, ReferenceError, etc.?).

My current testing framework

12条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 19:24

    In case you are working with Promises:

    await expect(Promise.reject(new HttpException('Error message', 402)))
      .rejects.toThrowError(HttpException);
    

提交回复
热议问题