Nestjs在E2E测试中获得404,但预计400(Chai& supertest)

发布于 2025-02-02 06:44:47 字数 874 浏览 4 评论 0原文

您好,其他程序员,我只是遇到了一个想吸引另一只眼睛的问题。

随着IM运行E2E测试,在此功能中

im遇到此错误

这似乎很奇怪,因为当我在摇摇晃晃或邮递员上测试时,请求的行为如您所见

这是我的模块在测试文件上

< img src =“ https://i.sstatic.net/mbpu6.png” alt =“在此处输入图像说明”>

您碰巧知道解决方案可能是什么吗? 另外,如果您需要更多信息,请告诉我,我将更新此问题。

已经确保其发送请求的地址正确。

Hello Fellow Programmers, i just bumped into a problem that would like to get another eyes into.

As im running e2e tests, in this function
enter image description here

im getting this error
enter image description here

Which seems odd, because when im testing on swagger or postman the request behaves as expected as you can see here
enter image description here

this is my module on the test file

enter image description here

Do you happen to know what the solution might be?, let me know below :)
Also, if you need more info just let me know and i'll update this question.

Already made sure that the address it's sending the request to is correct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日久见人心 2025-02-09 06:44:48

运行API调用时,服务器是否可能不会完全初始化?异步问题?

看那个测试模板,也许会起作用?抱歉,我无法测试,我正在打电话 /度假。

测试模板: https:// github .com/befabry/nest-car-value/blob/master/test/auth.e2e-spec.ts

Would it be possible that the server is not fully initialized when you run your API call? An asynchronous problem?

Look at that test template, maybe that would work? Sorry I cannot test, I'm on phone / vacation.

Test template : https://github.com/befabry/nest-car-value/blob/master/test/auth.e2e-spec.ts

秋日私语 2025-02-09 06:44:48

问题是我没有在控制器中正确传递请求主体,我对此求解了以下装饰器,该方法验证了身体并返回预期的400:

@usepipes(new验证Pipe) ,白名单:true}))

The problem was I wasn't passing the request body correctly in the controller, which i solved adding the following decorator to the method, which validates the body and returns the expected 400:

@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文