@@ -25,6 +25,11 @@ const TEST_PROVIDERS: (Provider | EnvironmentProviders)[] = [
2525] ;
2626
2727describe ( 'YoutubePlayer' , ( ) => {
28+ const ytWindow = window as Window &
29+ typeof globalThis & {
30+ YT ?: typeof YT | undefined ;
31+ onYouTubeIframeAPIReady ?: ( ( ) => void ) | undefined ;
32+ } ;
2833 let playerCtorSpy : jasmine . Spy ;
2934 let playerSpy : jasmine . SpyObj < YT . Player > ;
3035 let fixture : ComponentFixture < TestApp > ;
@@ -35,7 +40,7 @@ describe('YoutubePlayer', () => {
3540 const fake = createFakeYtNamespace ( ) ;
3641 playerCtorSpy = fake . playerCtorSpy ;
3742 playerSpy = fake . playerSpy ;
38- window . YT = fake . namespace ;
43+ ytWindow . YT = fake . namespace ;
3944 events = fake . events ;
4045 } ) ) ;
4146
@@ -58,8 +63,8 @@ describe('YoutubePlayer', () => {
5863 } ) ;
5964
6065 afterEach ( ( ) => {
61- window . YT = undefined ;
62- window . onYouTubeIframeAPIReady = undefined ;
66+ ytWindow . YT = undefined ! ;
67+ ytWindow . onYouTubeIframeAPIReady = undefined ;
6368 } ) ;
6469
6570 it ( 'initializes a youtube player when the placeholder is clicked' , ( ) => {
@@ -215,7 +220,7 @@ describe('YoutubePlayer', () => {
215220
216221 expect ( playerSpy . cueVideoById ) . not . toHaveBeenCalled ( ) ;
217222
218- playerSpy . getPlayerState . and . returnValue ( window . YT ! . PlayerState . CUED ) ;
223+ playerSpy . getPlayerState . and . returnValue ( ytWindow . YT ! . PlayerState . CUED ) ;
219224 events . onReady ( { target : playerSpy } ) ;
220225
221226 expect ( playerSpy . cueVideoById ) . toHaveBeenCalledWith (
@@ -542,17 +547,17 @@ describe('YoutubePlayer', () => {
542547 let api : typeof YT ;
543548
544549 beforeEach ( ( ) => {
545- api = window . YT ! ;
546- window . YT = undefined ;
550+ api = ytWindow . YT ! ;
551+ ytWindow . YT = undefined ! ;
547552 } ) ;
548553
549554 afterEach ( ( ) => {
550- window . YT = undefined ;
551- window . onYouTubeIframeAPIReady = undefined ;
555+ ytWindow . YT = undefined ! ;
556+ ytWindow . onYouTubeIframeAPIReady = undefined ;
552557 } ) ;
553558
554559 it ( 'waits until the api is ready before initializing' , ( ) => {
555- window . YT = YT_LOADING_STATE_MOCK ;
560+ ytWindow . YT = YT_LOADING_STATE_MOCK ;
556561 TestBed . configureTestingModule ( { providers : TEST_PROVIDERS } ) ;
557562 fixture = TestBed . createComponent ( TestApp ) ;
558563 testComponent = fixture . debugElement . componentInstance ;
@@ -562,8 +567,8 @@ describe('YoutubePlayer', () => {
562567
563568 expect ( playerCtorSpy ) . not . toHaveBeenCalled ( ) ;
564569
565- window . YT = api ;
566- window . onYouTubeIframeAPIReady ! ( ) ;
570+ ytWindow . YT = api ;
571+ ytWindow . onYouTubeIframeAPIReady ! ( ) ;
567572
568573 expect ( playerCtorSpy ) . toHaveBeenCalledWith (
569574 getVideoHost ( fixture ) ,
@@ -577,7 +582,7 @@ describe('YoutubePlayer', () => {
577582
578583 it ( 'should not override any pre-existing API loaded callbacks' , ( ) => {
579584 const spy = jasmine . createSpy ( 'other API loaded spy' ) ;
580- window . onYouTubeIframeAPIReady = spy ;
585+ ytWindow . onYouTubeIframeAPIReady = spy ;
581586 TestBed . configureTestingModule ( { providers : TEST_PROVIDERS } ) ;
582587 fixture = TestBed . createComponent ( TestApp ) ;
583588 testComponent = fixture . debugElement . componentInstance ;
@@ -587,8 +592,8 @@ describe('YoutubePlayer', () => {
587592
588593 expect ( playerCtorSpy ) . not . toHaveBeenCalled ( ) ;
589594
590- window . YT = api ;
591- window . onYouTubeIframeAPIReady ! ( ) ;
595+ ytWindow . YT = api ;
596+ ytWindow . onYouTubeIframeAPIReady ! ( ) ;
592597
593598 expect ( spy ) . toHaveBeenCalled ( ) ;
594599 } ) ;
@@ -603,7 +608,7 @@ describe('YoutubePlayer', () => {
603608 } ) ;
604609
605610 afterEach ( ( ) => {
606- fixture = testComponent = window . YT = window . onYouTubeIframeAPIReady = undefined ! ;
611+ fixture = testComponent = ytWindow . YT = ytWindow . onYouTubeIframeAPIReady = undefined ! ;
607612 } ) ;
608613
609614 it ( 'should show a placeholder' , ( ) => {
@@ -687,7 +692,7 @@ describe('YoutubePlayer', () => {
687692 fixture . detectChanges ( ) ;
688693
689694 // Simulate player state being PLAYING (autoplay has started the video)
690- playerSpy . getPlayerState . and . returnValue ( window . YT ! . PlayerState . PLAYING ) ;
695+ playerSpy . getPlayerState . and . returnValue ( ytWindow . YT ! . PlayerState . PLAYING ) ;
691696 events . onReady ( { target : playerSpy } ) ;
692697
693698 // Should use seekTo instead of cueVideoById when player is already playing
@@ -724,7 +729,7 @@ describe('YoutubePlayer', () => {
724729 getPlaceholder ( staticSecondsApp ) . click ( ) ;
725730 staticSecondsApp . detectChanges ( ) ;
726731
727- playerSpy . getPlayerState . and . returnValue ( window . YT ! . PlayerState . CUED ) ;
732+ playerSpy . getPlayerState . and . returnValue ( ytWindow . YT ! . PlayerState . CUED ) ;
728733 events . onReady ( { target : playerSpy } ) ;
729734
730735 expect ( playerSpy . cueVideoById ) . toHaveBeenCalledWith (
0 commit comments