1

我正在尝试使用 Sinon + Mocha + Nock 模拟 PATCH 请求。

以下是我为 nock 服务提供的代码:

nock("https://app-service.test.com")
  .filteringRequestBody((body) => {
    lastPatchData = body;
    return body;
  })
  .matchHeader("authorization", authToken)
  .matchHeader("accept", "application/json")
  .matchHeader("content-type", "application/json")
  .patch("/v1/app/" + itemId)
  .reply(200, app.patchSuccessResponse);

测试执行失败并出现以下错误响应(为便于阅读而格式化:

错误:Nock:与请求不匹配

相关请求负载:

{
    "method": "PATCH",
    "url": "https://app-service.test.com/v1/app/f1cd947a-70c6-4e8d-91ad-30535ef89194",
    "headers": {
        "authorization": "Bearer afhasjdhfjkhsadjkfns",
        "host": "app-service.test.com",
        "accept": "application/json",
        "content-type": "application/json",
        "content-length": 620
    },
    "body": {
        "state": "DEPLOYED"
    }
}
4

0 回答 0