@@ -89,6 +89,40 @@ describe('Request Overrider', () => {
8989 } )
9090 } )
9191
92+ it ( 'write callback called when encoding is not supplied' , done => {
93+ const scope = nock ( 'http://example.test' )
94+ . filteringRequestBody ( / m i a / , 'nostra' )
95+ . post ( '/' , 'mamma nostra' )
96+ . reply ( )
97+
98+ const reqWriteCallback = sinon . spy ( )
99+
100+ const req = http . request (
101+ {
102+ host : 'example.test' ,
103+ method : 'POST' ,
104+ path : '/' ,
105+ port : 80 ,
106+ } ,
107+ res => {
108+ expect ( reqWriteCallback ) . to . have . been . calledOnce ( )
109+ expect ( res . statusCode ) . to . equal ( 200 )
110+ res . on ( 'end' , ( ) => {
111+ scope . done ( )
112+ done ( )
113+ } )
114+ // Streams start in 'paused' mode and must be started.
115+ // See https://nodejs.org/api/stream.html#stream_class_stream_readable
116+ res . resume ( )
117+ }
118+ )
119+
120+ req . write ( 'mamma mia' , ( ) => {
121+ reqWriteCallback ( )
122+ req . end ( )
123+ } )
124+ } )
125+
92126 it ( 'write callback is not called if the provided chunk is undefined' , done => {
93127 const scope = nock ( 'http://example.test' ) . post ( '/' ) . reply ( )
94128
@@ -117,6 +151,34 @@ describe('Request Overrider', () => {
117151 req . end ( )
118152 } )
119153
154+ it ( "write doesn't throw if invoked w/o callback" , done => {
155+ const scope = nock ( 'http://example.test' ) . post ( '/' ) . reply ( )
156+
157+ const reqWriteCallback = sinon . spy ( )
158+
159+ const req = http . request (
160+ {
161+ host : 'example.test' ,
162+ method : 'POST' ,
163+ path : '/' ,
164+ } ,
165+ res => {
166+ expect ( res . statusCode ) . to . equal ( 200 )
167+ res . on ( 'end' , ( ) => {
168+ expect ( reqWriteCallback ) . to . not . have . been . called ( )
169+ scope . done ( )
170+ done ( )
171+ } )
172+ // Streams start in 'paused' mode and must be started.
173+ // See https://nodejs.org/api/stream.html#stream_class_stream_readable
174+ res . resume ( )
175+ }
176+ )
177+
178+ req . write ( undefined )
179+ req . end ( )
180+ } )
181+
120182 it ( 'end callback called' , done => {
121183 const scope = nock ( 'http://example.test' )
122184 . filteringRequestBody ( / m i a / , 'nostra' )
0 commit comments