You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running a unit test using Jest the validation pipeline is not triggered. The expected behaviour would be by providing incorrect values to a route which accepts a body that the validation pipe would be triggered and an error returned to the client.
// The input modelimport{IsNumber,IsNotEmpty,IsString,IsOptional}from'class-validator';exportclassUpdateAlbumInputModel{
@IsNotEmpty()
@IsNumber()albumId: number;
@IsOptional()
@IsString()description?: string;
@IsNotEmpty()
@IsString()name: string}// The route
@Put('/albums')
@HttpCode(204)publicasyncupdateAlbums(
@Body(ValidationPipe)body: UpdateAlbumInputModel){returnawaitthis.albumService.updateAlbums(body);}
The unit test can be found here:
it('should fail to update albums, if the body is invalid',async()=>{awaittestApiHandler({handler: albumHandler,url: '/api/albums',test: async({ fetch })=>{constres=awaitfetch({method: 'PUT',body: JSON.stringify({description: 'description',}),headers: {'Content-Type': 'application/json',},});// This returns a 204 status code, but expected to return an invalid status code of 400 (Bad Request)console.log(res);},});});
The problem
When running a unit test using Jest the validation pipeline is not triggered. The expected behaviour would be by providing incorrect values to a route which accepts a body that the validation pipe would be triggered and an error returned to the client.
The unit test can be found here:
Additional context
Package versions:
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"next-api-decorators": "2.0.2",
The text was updated successfully, but these errors were encountered: