如何向Nock添加自定义错误

时间:2018-08-02 12:34:21

标签: node.js unit-testing mocking chai nock

我正在使用Nock库创建服务器模拟。我未能为此模拟添加错误作为响应正文,我编写了以下内容

 nock(httpMock.httpGetRequest.baseUrl)
  .get(httpMock.httpGetRequest.path)
   .reply(500, httpMock.httpGetRequest.testError)

未定义检索的结果。

但是如果成功的话,我打算使用chai来期待这个结果

 expect(await httpHelper.get(httpMock.req,httpMock.httpGetRequest.fullUrl)).to.throw(httpMock.httpGetRequest.testError)

我可以使用replyWithError,但是我不需要它,因为我需要原始状态码,但具有自定义属性。 请告知

0 个答案:

没有答案