@@ -247,6 +247,45 @@ describe("NodeHttpHandler", () => {
247247 } ) ;
248248 } ) ;
249249
250+ describe ( "create" , ( ) => {
251+ const randomRequestTimeout = Math . round ( Math . random ( ) * 10000 ) + 1 ;
252+
253+ it . each ( [
254+ [ "existing handler instance" , new NodeHttpHandler ( ) ] ,
255+ [ "custom HttpHandler object" , {
256+ handle : vi . fn ( ) ,
257+ metadata : { handlerProtocol : "custom" } ,
258+ updateHttpClientConfig : vi . fn ( ) ,
259+ httpHandlerConfigs : vi . fn ( ) ,
260+ } ] ,
261+ ] ) ( "returns the input handler when passed %s" , ( _ , handler ) => {
262+ const result = NodeHttpHandler . create ( handler ) ;
263+ expect ( result ) . toBe ( handler ) ;
264+ } ) ;
265+
266+ it . each ( [
267+ [ "undefined" , undefined ] ,
268+ [ "an empty options hash" , { } ] ,
269+ [ "empty provider" , async ( ) => undefined ] ,
270+ ] ) ( "creates new handler instance when input is %s" , async ( _ , input ) => {
271+ const result = NodeHttpHandler . create ( input ) ;
272+ expect ( result ) . toBeInstanceOf ( NodeHttpHandler ) ;
273+ } ) ;
274+
275+ it . each ( [
276+ [ "an options hash" , { requestTimeout : randomRequestTimeout } ] ,
277+ [ "a provider" , async ( ) => ( { requestTimeout : randomRequestTimeout } ) ] ,
278+ ] ) ( "creates new handler instance with config when input is %s" , async ( _ , input ) => {
279+ const result = NodeHttpHandler . create ( input ) ;
280+ expect ( result ) . toBeInstanceOf ( NodeHttpHandler ) ;
281+
282+ // Verify configuration by calling handle
283+ await result . handle ( { } as any ) ;
284+
285+ expect ( result . httpHandlerConfigs ( ) . requestTimeout ) . toBe ( randomRequestTimeout ) ;
286+ } ) ;
287+ } ) ;
288+
250289 describe ( "#destroy" , ( ) => {
251290 it ( "should be callable and return nothing" , ( ) => {
252291 const nodeHttpHandler = new NodeHttpHandler ( ) ;
0 commit comments