@@ -107,7 +107,20 @@ test("setScript adds a script to head with valid src", async () => {
107107 const script = document . head . childNodes [ 0 ] as HTMLScriptElement ;
108108
109109 expect ( script . src ) . toEqual (
110- "https://maps.googleapis.com/maps/api/js?libraries=&key=foo&callback=google.maps.__ib__"
110+ "https://maps.googleapis.com/maps/api/js?libraries=core&key=foo&callback=google.maps.__ib__"
111+ ) ;
112+ } ) ;
113+
114+ test ( "setScript adds a script to head with valid src with libraries" , async ( ) => {
115+ const loader = new Loader ( { apiKey : "foo" , libraries : [ "marker" , "places" ] } ) ;
116+
117+ loader [ "setScript" ] ( ) ;
118+ await 0 ;
119+
120+ const script = document . head . childNodes [ 0 ] as HTMLScriptElement ;
121+
122+ expect ( script . src ) . toEqual (
123+ "https://maps.googleapis.com/maps/api/js?libraries=marker%2Cplaces&key=foo&callback=google.maps.__ib__"
111124 ) ;
112125} ) ;
113126
@@ -184,6 +197,7 @@ test("script onerror should retry", async () => {
184197
185198 // wait for the first failure
186199 await 0 ;
200+ await 0 ;
187201 expect ( loader [ "errors" ] . length ) . toBe ( 1 ) ;
188202 // trigger the retry delay:
189203 jest . runAllTimers ( ) ;
@@ -207,6 +221,7 @@ test("script onerror should reset retry mechanism with next loader", async () =>
207221 let rejection = expect ( loader . load ( ) ) . rejects . toBeInstanceOf ( Error ) ;
208222 // wait for the first first failure
209223 await 0 ;
224+ await 0 ;
210225 expect ( loader [ "errors" ] . length ) . toBe ( 1 ) ;
211226 // trigger the retry delay:
212227 jest . runAllTimers ( ) ;
@@ -221,6 +236,7 @@ test("script onerror should reset retry mechanism with next loader", async () =>
221236
222237 // wait for the second first failure
223238 await 0 ;
239+ await 0 ;
224240 expect ( loader [ "errors" ] . length ) . toBe ( 1 ) ;
225241 // trigger the retry delay:
226242 jest . runAllTimers ( ) ;
@@ -241,6 +257,7 @@ test("script onerror should not reset retry mechanism with parallel loaders", as
241257 const rejection2 = expect ( loader . load ( ) ) . rejects . toBeInstanceOf ( Error ) ;
242258 // wait for the first first failure
243259 await 0 ;
260+ await 0 ;
244261 jest . runAllTimers ( ) ;
245262
246263 await Promise . all ( [ rejection1 , rejection2 ] ) ;
@@ -404,3 +421,29 @@ test("importLibrary resolves correctly", async () => {
404421 const core = await corePromise ;
405422 expect ( core ) . toEqual ( { core : "fake" } ) ;
406423} ) ;
424+
425+ test ( "importLibrary can also set up bootstrap libraries (if bootstrap libraries empty)" , async ( ) => {
426+ const loader = new Loader ( { apiKey : "foo" } ) ;
427+ loader . importLibrary ( "marker" ) ;
428+ loader . importLibrary ( "places" ) ;
429+
430+ await 0 ;
431+
432+ const script = document . head . childNodes [ 0 ] as HTMLScriptElement ;
433+
434+ expect ( script . src ) . toEqual (
435+ "https://maps.googleapis.com/maps/api/js?libraries=core%2Cmarker%2Cplaces&key=foo&callback=google.maps.__ib__"
436+ ) ;
437+ } ) ;
438+
439+ test ( "importLibrary resolves correctly even with different bootstrap libraries" , async ( ) => {
440+ window . google = { maps : { } } as any ;
441+ google . maps . importLibrary = async ( name ) => ( { [ name ] : "fake" } as any ) ;
442+
443+ const loader = new Loader ( { apiKey : "foo" , libraries : [ "places" ] } ) ;
444+ const corePromise = loader . importLibrary ( "core" ) ;
445+
446+ const core = await corePromise ;
447+ expect ( core ) . toEqual ( { core : "fake" } ) ;
448+ expect ( await loader . importLibrary ( "places" ) ) . toEqual ( { places : "fake" } ) ;
449+ } ) ;
0 commit comments