Body validation is not working
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When using https://github.com/nestjs/nest/tree/master/sample/01-cats-app example, doing POST / with empty body doesn’t trigger validation/doesn’t result in 400 Bad Request error.
Expected behavior
Test fails, as HTTP request returns error 400 (as described in https://docs.nestjs.com/techniques/validation).
Minimal reproduction of the problem with instructions
I have changed create method to
@Post() //@Roles(‘admin’) async create(@Body() createCatDto: CreateCatDto) { //this.catsService.create(createCatDto); }
and added a test case
it(/POST cats
, () => {
return request(app.getHttpServer())
.post(‘/cats’)
.expect(201);
});
to https://github.com/nestjs/nest/blob/master/sample/01-cats-app/e2e/cats/cats.e2e-spec.ts
What is the motivation / use case for changing the behavior?
Because request validation is importtan and critical feature (and according to documentation it supposed to work).
Environment
Nest version: Cloned repo from https://github.com/nestjs/nest/commit/5e2727bf905cc3a4ca26267c6a385793088ff43e
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Create a helper function which takes
app
as an argument and applies configuration (pipes etc).Tests aren’t using
ValidationPipe
, see https://github.com/aeremin/nest/blob/a519f02b4482e28f6e93a355593a703a682bc927/sample/01-cats-app/e2e/cats/cats.e2e-spec.ts#L12-L21 Add: