@@ -2,10 +2,16 @@ import { TestBed, async, ComponentFixture } from '@angular/core/testing';
22import { NO_ERRORS_SCHEMA , CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
33import { By } from '@angular/platform-browser' ;
44
5+ import { WindowRef } from '@thisissoon/angular-inviewport' ;
6+
57import { ImageLoaderComponent } from './image-loader.component' ;
68import { Breakpoint , ResponsiveImage } from './shared/image.model' ;
79import { ImageLoadedEvent } from './index' ;
810
11+ class MockWindowRef {
12+ public innerWidth = 800 ;
13+ }
14+
915describe ( 'ImageLoaderComponent' , ( ) => {
1016 let fixture : ComponentFixture < ImageLoaderComponent > ;
1117 let component : ImageLoaderComponent ;
@@ -40,7 +46,10 @@ describe('ImageLoaderComponent', () => {
4046 ] ,
4147 declarations : [
4248 ImageLoaderComponent
43- ]
49+ ] ,
50+ providers : [
51+ { provide : WindowRef , useClass : MockWindowRef }
52+ ] ,
4453 } ) . compileComponents ( ) ;
4554 } ) ) ;
4655
@@ -52,13 +61,17 @@ describe('ImageLoaderComponent', () => {
5261 fixture . detectChanges ( ) ;
5362 } ) ;
5463
64+ it ( 'should update size based on window ref object on init' , ( ) => {
65+ expect ( component . size ) . toEqual ( 'md' ) ;
66+ } ) ;
67+
5568 it ( 'should set placeholder on init' , ( ) => {
5669 const spy = spyOn ( component , 'setPlaceholder' ) ;
5770 component . ngOnInit ( ) ;
5871 expect ( spy ) . toHaveBeenCalled ( ) ;
5972 } ) ;
6073
61- it ( 'should set fire placeholder loaded event on image load when loaded is false' , ( ) => {
74+ it ( 'should fire placeholder loaded event on image load when loaded is false' , ( ) => {
6275 const spy = spyOn ( component . imagePlaceholderLoaded , 'emit' ) ;
6376 component . loaded = false ;
6477 const imageElement = fixture . debugElement . query ( By . css ( 'img' ) ) ;
@@ -168,4 +181,5 @@ describe('ImageLoaderComponent', () => {
168181 component . ngOnDestroy ( ) ;
169182 expect ( spy ) . toHaveBeenCalled ( ) ;
170183 } ) ;
184+
171185} ) ;
0 commit comments