@@ -69,11 +69,11 @@ test('appends a header correctly with no existing one', () => {
69
69
} ) ;
70
70
71
71
test ( 'calls express response correctly' , ( ) => {
72
- const mockRes = ( {
72
+ const mockRes = {
73
73
status : jest . fn ( ) ,
74
74
set : jest . fn ( ) ,
75
75
send : jest . fn ( ) ,
76
- } as unknown ) as ExpressResponse ;
76
+ } as unknown as ExpressResponse ;
77
77
const response = new Response ( ) ;
78
78
response . setBody ( `I'm a teapot!` ) ;
79
79
response . setStatusCode ( 418 ) ;
@@ -84,3 +84,31 @@ test('calls express response correctly', () => {
84
84
expect ( mockRes . status ) . toHaveBeenCalledWith ( 418 ) ;
85
85
expect ( mockRes . set ) . toHaveBeenCalledWith ( { 'Content-Type' : 'text/plain' } ) ;
86
86
} ) ;
87
+
88
+ test ( 'serializes a response' , ( ) => {
89
+ const response = new Response ( ) ;
90
+ response . setBody ( "I'm a teapot!" ) ;
91
+ response . setStatusCode ( 418 ) ;
92
+ response . appendHeader ( 'Content-Type' , 'text/plain' ) ;
93
+
94
+ const serialized = response . serialize ( ) ;
95
+
96
+ expect ( serialized . body ) . toEqual ( "I'm a teapot!" ) ;
97
+ expect ( serialized . statusCode ) . toEqual ( 418 ) ;
98
+ expect ( serialized . headers ) . toEqual ( { 'Content-Type' : 'text/plain' } ) ;
99
+ } ) ;
100
+
101
+ test ( 'serializes a response with content type set to application/json' , ( ) => {
102
+ const response = new Response ( ) ;
103
+ response . setBody ( { url : 'https://dkundel.com' } ) ;
104
+ response . setStatusCode ( 200 ) ;
105
+ response . appendHeader ( 'Content-Type' , 'application/json' ) ;
106
+
107
+ const serialized = response . serialize ( ) ;
108
+
109
+ expect ( serialized . body ) . toEqual (
110
+ JSON . stringify ( { url : 'https://dkundel.com' } )
111
+ ) ;
112
+ expect ( serialized . statusCode ) . toEqual ( 200 ) ;
113
+ expect ( serialized . headers ) . toEqual ( { 'Content-Type' : 'application/json' } ) ;
114
+ } ) ;
0 commit comments