File tree 2 files changed +25
-8
lines changed
2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -425,6 +425,23 @@ test("importLibrary resolves correctly", async () => {
425
425
expect ( core ) . toEqual ( { core : "fake" } ) ;
426
426
} ) ;
427
427
428
+ test ( "importLibrary resolves correctly without warning with sequential await" , async ( ) => {
429
+ console . warn = jest . fn ( ) ;
430
+ window . google = { maps : { } } as any ;
431
+ google . maps . importLibrary = async ( name ) => {
432
+ google . maps . version = "3.*.*" ;
433
+ return { [ name ] : "fake" } as any ;
434
+ } ;
435
+
436
+ const loader = new Loader ( { apiKey : "foo" } ) ;
437
+ const core = await loader . importLibrary ( "core" ) ;
438
+ const marker = await loader . importLibrary ( "marker" ) ;
439
+
440
+ expect ( console . warn ) . toHaveBeenCalledTimes ( 0 ) ;
441
+ expect ( core ) . toEqual ( { core : "fake" } ) ;
442
+ expect ( marker ) . toEqual ( { marker : "fake" } ) ;
443
+ } ) ;
444
+
428
445
test ( "importLibrary can also set up bootstrap libraries (if bootstrap libraries empty)" , async ( ) => {
429
446
const loader = new Loader ( { apiKey : "foo" } ) ;
430
447
loader . importLibrary ( "marker" ) ;
Original file line number Diff line number Diff line change @@ -623,26 +623,26 @@ export class Loader {
623
623
private execute ( ) : void {
624
624
this . resetIfRetryingFailed ( ) ;
625
625
626
+ if ( this . loading ) {
627
+ // do nothing but wait
628
+ return ;
629
+ }
630
+
626
631
if ( this . done ) {
627
632
this . callback ( ) ;
628
633
} else {
629
634
// short circuit and warn if google.maps is already loaded
630
635
if ( window . google && window . google . maps && window . google . maps . version ) {
631
636
console . warn (
632
- "Google Maps already loaded outside @googlemaps/js-api-loader." +
637
+ "Google Maps already loaded outside @googlemaps/js-api-loader. " +
633
638
"This may result in undesirable behavior as options and script parameters may not match."
634
639
) ;
635
640
this . callback ( ) ;
636
641
return ;
637
642
}
638
643
639
- if ( this . loading ) {
640
- // do nothing but wait
641
- } else {
642
- this . loading = true ;
643
-
644
- this . setScript ( ) ;
645
- }
644
+ this . loading = true ;
645
+ this . setScript ( ) ;
646
646
}
647
647
}
648
648
}
You can’t perform that action at this time.
0 commit comments