gpt4 book ai didi

node.js - supertest 测试删除方法返回 404 但 restful 客户端工作

转载 作者:搜寻专家 更新时间:2023-11-01 00:09:37 30 4
gpt4 key购买 nike

我使用 supertest 来测试我的 api,删除端点在使用一些 restful 客户端(例如 postman)进行测试时工作正常,但在 supertest 中失败。

it('should return 200', function (done) {
request(app)
.del('/v1/xxxx/' + id)
.expect('Content-Type', /json/)
.expect(200, done);
});

但是当我添加时它通过了测试

it('should return 200', function (done) {
request(app)
.del('/v1/xxxx/' + id)
.send({})
.expect('Content-Type', /json/)
.expect(200, done);
});

有人能告诉我为什么吗?

最佳答案

从您的帖子中不清楚这个问题到底是什么。最有可能的是 '/v1/xxxx/' url 不正确。难道是'/api/..../v1/xxx/'+id ????

在我自己的案例中,这就是问题所在。并且我可以报告 supertest 的工作完全符合 .del(...) 或 .delete(....) 的预期。

我希望这能帮助遇到这个问题的其他人。

关于node.js - supertest 测试删除方法返回 404 但 restful 客户端工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25681137/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com