Nestjs在E2E测试中获得404,但预计400(Chai& supertest)
您好,其他程序员,我只是遇到了一个想吸引另一只眼睛的问题。
这似乎很奇怪,因为当我在摇摇晃晃或邮递员上测试时,请求的行为如您所见
这是我的模块在测试文件上
< 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
Which seems odd, because when im testing on swagger or postman the request behaves as expected as you can see here
this is my module on the test file
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行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
问题是我没有在控制器中正确传递请求主体,我对此求解了以下装饰器,该方法验证了身体并返回预期的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 }))