以下是可以执行以复制问题的场景-
Scenario: get all posts
* url 'https://reqres.in/'
Given path '/api/users/2'
When method delete
Then status 204
And match response.id == '#null'
And match response.time == '#present'
对于该请求,只有响应头,没有响应正文。但是上面验证 null 和字段存在的断言正在通过。
根据空手道文档,这两个断言都期望存在 JSON 密钥。基于此,我预计即使没有响应主体,断言也会失败。这是空手道的错误吗?
这里的响应不是 JSON,所以那些
#present
类型的断言将不起作用。建议始终使用 JSON 对象进行匹配。例如:
* match response == { id: '#null', time: '#present' }
这可以避免您遇到的问题。无论如何,我们提出了一个问题,它提供了更多解释:https://github.com/karatelabs/karate/issues/2406