@@ -21,6 +21,8 @@ const diagnosticOrigin = {
2121
2222const diagnosticLogger = {
2323 debug ( ) {
24+ } ,
25+ error ( ) {
2426 }
2527} ;
2628
@@ -54,11 +56,15 @@ function prepareDiagnostic() {
5456 mock . method ( diagnosticOrigin , 'body' ) ;
5557 mock . method ( diagnosticOrigin , 'headers' ) ;
5658
57- diagnosticLogger . message = null ;
59+ diagnosticLogger . options = { } ;
5860 diagnosticLogger . debug = ( message ) => {
59- diagnosticLogger . message = message ;
61+ diagnosticLogger . options . message = message ;
62+ } ;
63+ diagnosticLogger . error = ( message ) => {
64+ diagnosticLogger . options . error = message ;
6065 } ;
6166 mock . method ( diagnosticLogger , 'debug' ) ;
67+ mock . method ( diagnosticLogger , 'error' ) ;
6268}
6369
6470function resetDiagnostic ( ) {
@@ -144,18 +150,34 @@ describe('LoggedInputRequest', () => {
144150 beforeEach ( prepareDiagnostic ) ;
145151 afterEach ( resetDiagnostic ) ;
146152
153+ it ( 'should call flush of origin' , async ( ) => {
154+ await new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ;
155+
156+ assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 1 ) ;
157+ } ) ;
158+
147159 it ( 'should call debug of logger' , async ( ) => {
148160 await new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ;
149161
150162 assert . strictEqual ( diagnosticLogger . debug . mock . calls . length , 1 ) ;
151163 } ) ;
152164
153- it ( 'should call flush of origin' , async ( ) => {
165+ it ( 'should call error of logger' , async ( ) => {
166+ diagnosticOrigin . flush = ( ) => { throw new Error ( 'flush error' ) } ;
167+ mock . method ( diagnosticOrigin , 'flush' ) ;
168+
169+ await assert . rejects ( ( ) => new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ) ;
170+
171+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 1 ) ;
172+ } ) ;
173+
174+ it ( 'should not call error of logger' , async ( ) => {
154175 await new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ;
155176
156- assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 1 ) ;
177+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 0 ) ;
157178 } ) ;
158179
180+
159181 it ( 'should fall when call debug of logger, cause null' , async ( ) => {
160182 await assert . rejects ( ( ) => new LoggedInputRequest ( null , null , { } ) . flush ( ) ,
161183 { name : 'TypeError' } ) ;
@@ -178,11 +200,15 @@ describe('LoggedInputRequest', () => {
178200 } ) ;
179201
180202 it ( 'should fall when call flush of origin, cause null' , async ( ) => {
181- await assert . rejects ( ( ) => new LoggedInputRequest ( null , diagnosticLogger , { } ) . flush ( ) ,
203+ await assert . rejects ( ( ) => new LoggedInputRequest (
204+ null , diagnosticLogger , { method : 'method' , url : 'url' }
205+ ) . flush ( ) ,
182206 { name : 'TypeError' } ) ;
183207
184208 assert . strictEqual ( diagnosticLogger . debug . mock . calls . length , 1 ) ;
185209 assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 0 ) ;
210+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 1 ) ;
211+ assert . strictEqual ( diagnosticLogger . options . error . includes ( 'HttpRequest: [method] url error:' ) , true )
186212 } ) ;
187213
188214 it ( 'should fall when call flush of origin, cause error' , async ( ) => {
@@ -191,11 +217,15 @@ describe('LoggedInputRequest', () => {
191217 } ;
192218 mock . method ( diagnosticOrigin , 'flush' ) ;
193219
194- await assert . rejects ( ( ) => new LoggedInputRequest ( diagnosticOrigin , diagnosticLogger , { } ) . flush ( ) ,
220+ await assert . rejects ( ( ) => new LoggedInputRequest (
221+ diagnosticOrigin , diagnosticLogger , { method : 'method' , url : 'url' }
222+ ) . flush ( ) ,
195223 { message : 'flush error' } ) ;
196224
197225 assert . strictEqual ( diagnosticLogger . debug . mock . calls . length , 1 ) ;
198226 assert . strictEqual ( diagnosticOrigin . flush . mock . calls . length , 1 ) ;
227+ assert . strictEqual ( diagnosticLogger . error . mock . calls . length , 1 ) ;
228+ assert . strictEqual ( diagnosticLogger . options . error . includes ( 'HttpRequest: [method] url error: flush error' ) , true )
199229 } ) ;
200230
201231 it ( 'should log correct message' , async ( ) => {
@@ -205,7 +235,7 @@ describe('LoggedInputRequest', () => {
205235 headers : { header : 'header' }
206236 } ) . flush ( ) ;
207237
208- assert . strictEqual ( diagnosticLogger . message , 'HttpRequest: [method] url {"header":"header"}' ) ;
238+ assert . strictEqual ( diagnosticLogger . options . message , 'HttpRequest: [method] url {"header":"header"}' ) ;
209239 } ) ;
210240
211241 it ( 'should return another LoggedInputRequest' , async ( ) => {
0 commit comments