-1

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.

2 Answers2

0

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

befabry
  • 672
  • 5
  • 13
0

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 }))

  • I don't think you should have to do that. Normally NestJS takes care of it if you set it up globally through the main.ts entry file. How to set it up : https://docs.nestjs.com/techniques/validation#auto-validation= app.useGlobalPipes(new ValidationPipe()); – befabry May 30 '22 at 10:23