@@ -22,6 +22,35 @@ test('should parse JSON body', async () => {
22
22
} ) . expect ( 200 , { hello : 'world' } )
23
23
} )
24
24
25
+ test ( 'should ignore JSON empty body' , async ( ) => {
26
+ const server = createServer ( async ( req : ReqWithBody , res ) => {
27
+ await json ( ) ( req , res , ( err ) => void err && console . log ( err ) )
28
+
29
+ res . setHeader ( 'Content-Type' , 'application/json' )
30
+
31
+ res . end ( JSON . stringify ( { ok : true } ) ) ;
32
+ } )
33
+
34
+ // Empty string body
35
+ await makeFetch ( server ) ( '/' , {
36
+ body : '' ,
37
+ method : 'POST' ,
38
+ headers : {
39
+ Accept : 'application/json' ,
40
+ 'Content-Type' : 'application/json' ,
41
+ } ,
42
+ } ) . expect ( 200 , { ok : true } )
43
+
44
+ // Unset body
45
+ await makeFetch ( server ) ( '/' , {
46
+ method : 'POST' ,
47
+ headers : {
48
+ Accept : 'application/json' ,
49
+ 'Content-Type' : 'application/json' ,
50
+ } ,
51
+ } ) . expect ( 200 , { ok : true } )
52
+ } )
53
+
25
54
test ( 'should parse json body with no content-type headers' , async ( ) => {
26
55
const server = createServer ( async ( req : ReqWithBody , res ) => {
27
56
await json ( ) ( req , res , ( err ) => void err && console . log ( err ) )
0 commit comments