@@ -28,6 +28,14 @@ const contract = c.router({
2828 } ) ,
2929 } ,
3030 } ,
31+ noContent : {
32+ method : 'POST' ,
33+ path : '/no-content' ,
34+ body : c . noBody ( ) ,
35+ responses : {
36+ 204 : c . noBody ( ) ,
37+ } ,
38+ } ,
3139 testPathParams : {
3240 method : 'GET' ,
3341 path : '/test/:id' ,
@@ -73,6 +81,12 @@ describe('ts-rest-fastify', () => {
7381 } ,
7482 } ;
7583 } ) ,
84+ noContent : async ( ) => {
85+ return {
86+ status : 204 ,
87+ body : undefined ,
88+ } ;
89+ } ,
7690 testPathParams : async ( { params } ) => {
7791 return {
7892 status : 200 ,
@@ -183,6 +197,23 @@ describe('ts-rest-fastify', () => {
183197 } ) ;
184198 } ) ;
185199
200+ it ( 'should handle no content response' , async ( ) => {
201+ const app = fastify ( { logger : false } ) ;
202+
203+ s . registerRouter ( contract , router , app , {
204+ logInitialization : false ,
205+ } ) ;
206+
207+ await app . ready ( ) ;
208+
209+ const response = await supertest ( app . server ) . post ( '/no-content' ) ;
210+
211+ expect ( response . statusCode ) . toEqual ( 204 ) ;
212+ expect ( response . text ) . toEqual ( '' ) ;
213+ expect ( response . header [ 'content-type' ] ) . toBeUndefined ( ) ;
214+ expect ( response . header [ 'content-length' ] ) . toBeUndefined ( ) ;
215+ } ) ;
216+
186217 it ( "should allow for custom error handler if body doesn't match" , async ( ) => {
187218 const app = fastify ( { logger : false } ) ;
188219
@@ -433,6 +464,9 @@ describe('ts-rest-fastify', () => {
433464 ping : async ( ) => {
434465 throw new Error ( 'not implemented' ) ;
435466 } ,
467+ noContent : async ( ) => {
468+ throw new Error ( 'not implemented' ) ;
469+ } ,
436470 testPathParams : async ( ) => {
437471 throw new Error ( 'not implemented' ) ;
438472 } ,
0 commit comments