@@ -2,10 +2,16 @@ import { TestBed, async, ComponentFixture } from '@angular/core/testing';
2
2
import { NO_ERRORS_SCHEMA , CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
5
+ import { WindowRef } from '@thisissoon/angular-inviewport' ;
6
+
5
7
import { ImageLoaderComponent } from './image-loader.component' ;
6
8
import { Breakpoint , ResponsiveImage } from './shared/image.model' ;
7
9
import { ImageLoadedEvent } from './index' ;
8
10
11
+ class MockWindowRef {
12
+ public innerWidth = 800 ;
13
+ }
14
+
9
15
describe ( 'ImageLoaderComponent' , ( ) => {
10
16
let fixture : ComponentFixture < ImageLoaderComponent > ;
11
17
let component : ImageLoaderComponent ;
@@ -40,7 +46,10 @@ describe('ImageLoaderComponent', () => {
40
46
] ,
41
47
declarations : [
42
48
ImageLoaderComponent
43
- ]
49
+ ] ,
50
+ providers : [
51
+ { provide : WindowRef , useClass : MockWindowRef }
52
+ ] ,
44
53
} ) . compileComponents ( ) ;
45
54
} ) ) ;
46
55
@@ -52,13 +61,17 @@ describe('ImageLoaderComponent', () => {
52
61
fixture . detectChanges ( ) ;
53
62
} ) ;
54
63
64
+ it ( 'should update size based on window ref object on init' , ( ) => {
65
+ expect ( component . size ) . toEqual ( 'md' ) ;
66
+ } ) ;
67
+
55
68
it ( 'should set placeholder on init' , ( ) => {
56
69
const spy = spyOn ( component , 'setPlaceholder' ) ;
57
70
component . ngOnInit ( ) ;
58
71
expect ( spy ) . toHaveBeenCalled ( ) ;
59
72
} ) ;
60
73
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' , ( ) => {
62
75
const spy = spyOn ( component . imagePlaceholderLoaded , 'emit' ) ;
63
76
component . loaded = false ;
64
77
const imageElement = fixture . debugElement . query ( By . css ( 'img' ) ) ;
@@ -168,4 +181,5 @@ describe('ImageLoaderComponent', () => {
168
181
component . ngOnDestroy ( ) ;
169
182
expect ( spy ) . toHaveBeenCalled ( ) ;
170
183
} ) ;
184
+
171
185
} ) ;
0 commit comments