11import { Component , ViewChild , ChangeDetectionStrategy } from '@angular/core' ;
2- import { ComponentFixture , TestBed , fakeAsync , flush } from '@angular/core/testing' ;
2+ import { ComponentFixture , fakeAsync , flush , TestBed } from '@angular/core/testing' ;
33
44import { DEFAULT_OPTIONS , GoogleMap } from '../google-map/google-map' ;
55import { MapMarker } from '../map-marker/map-marker' ;
@@ -51,6 +51,7 @@ describe('DeprecatedMapMarkerClusterer', () => {
5151 ( window as any ) . MarkerClusterer = undefined ;
5252 } ) ;
5353
54+ // We can't test this one easily without `fakeAsync`.
5455 it ( 'throws an error if the clustering library has not been loaded' , fakeAsync ( ( ) => {
5556 ( window as any ) . MarkerClusterer = undefined ;
5657 markerClustererConstructorSpy = createDeprecatedMarkerClustererConstructorSpy (
@@ -64,9 +65,10 @@ describe('DeprecatedMapMarkerClusterer', () => {
6465 } ) . toThrowError ( / M a r k e r C l u s t e r e r c l a s s n o t f o u n d , c a n n o t c o n s t r u c t a m a r k e r c l u s t e r / ) ;
6566 } ) ) ;
6667
67- it ( 'initializes a Google Map Marker Clusterer' , fakeAsync ( ( ) => {
68+ it ( 'initializes a Google Map Marker Clusterer' , async ( ) => {
6869 fixture . detectChanges ( ) ;
69- flush ( ) ;
70+ await fixture . whenStable ( ) ;
71+ await wait ( 50 ) ;
7072
7173 expect ( markerClustererConstructorSpy ) . toHaveBeenCalledWith ( mapSpy , [ ] , {
7274 ariaLabelFn : undefined ,
@@ -88,9 +90,9 @@ describe('DeprecatedMapMarkerClusterer', () => {
8890 zIndex : undefined ,
8991 zoomOnClick : undefined ,
9092 } ) ;
91- } ) ) ;
93+ } ) ;
9294
93- it ( 'sets marker clusterer inputs' , fakeAsync ( ( ) => {
95+ it ( 'sets marker clusterer inputs' , async ( ) => {
9496 fixture . componentInstance . ariaLabelFn = ( testString : string ) => testString ;
9597 fixture . componentInstance . averageCenter = true ;
9698 fixture . componentInstance . batchSize = 1 ;
@@ -109,7 +111,8 @@ describe('DeprecatedMapMarkerClusterer', () => {
109111 fixture . componentInstance . zoomOnClick = true ;
110112 fixture . changeDetectorRef . markForCheck ( ) ;
111113 fixture . detectChanges ( ) ;
112- flush ( ) ;
114+ await fixture . whenStable ( ) ;
115+ await wait ( 50 ) ;
113116
114117 expect ( markerClustererConstructorSpy ) . toHaveBeenCalledWith ( mapSpy , [ ] , {
115118 ariaLabelFn : jasmine . any ( Function ) ,
@@ -131,11 +134,12 @@ describe('DeprecatedMapMarkerClusterer', () => {
131134 zIndex : 6 ,
132135 zoomOnClick : true ,
133136 } ) ;
134- } ) ) ;
137+ } ) ;
135138
136- it ( 'sets marker clusterer options' , fakeAsync ( ( ) => {
139+ it ( 'sets marker clusterer options' , async ( ) => {
137140 fixture . detectChanges ( ) ;
138- flush ( ) ;
141+ await fixture . whenStable ( ) ;
142+ await wait ( 50 ) ;
139143 const options : MarkerClustererOptions = {
140144 enableRetinaIcons : true ,
141145 gridSize : 1337 ,
@@ -145,12 +149,15 @@ describe('DeprecatedMapMarkerClusterer', () => {
145149 fixture . componentInstance . options = options ;
146150 fixture . changeDetectorRef . markForCheck ( ) ;
147151 fixture . detectChanges ( ) ;
152+ await fixture . whenStable ( ) ;
153+ await wait ( 50 ) ;
148154 expect ( markerClustererSpy . setOptions ) . toHaveBeenCalledWith ( jasmine . objectContaining ( options ) ) ;
149- } ) ) ;
155+ } ) ;
150156
151- it ( 'gives precedence to specific inputs over options' , fakeAsync ( ( ) => {
157+ it ( 'gives precedence to specific inputs over options' , async ( ) => {
152158 fixture . detectChanges ( ) ;
153- flush ( ) ;
159+ await fixture . whenStable ( ) ;
160+ await wait ( 50 ) ;
154161 const options : MarkerClustererOptions = {
155162 enableRetinaIcons : true ,
156163 gridSize : 1337 ,
@@ -170,25 +177,29 @@ describe('DeprecatedMapMarkerClusterer', () => {
170177 fixture . componentInstance . options = options ;
171178 fixture . changeDetectorRef . markForCheck ( ) ;
172179 fixture . detectChanges ( ) ;
180+ await fixture . whenStable ( ) ;
181+ await wait ( 50 ) ;
173182
174183 expect ( markerClustererSpy . setOptions ) . toHaveBeenCalledWith (
175184 jasmine . objectContaining ( expectedOptions ) ,
176185 ) ;
177- } ) ) ;
186+ } ) ;
178187
179- it ( 'sets Google Maps Markers in the MarkerClusterer' , fakeAsync ( ( ) => {
188+ it ( 'sets Google Maps Markers in the MarkerClusterer' , async ( ) => {
180189 fixture . detectChanges ( ) ;
181- flush ( ) ;
190+ await fixture . whenStable ( ) ;
191+ await wait ( 50 ) ;
182192
183193 expect ( markerClustererSpy . addMarkers ) . toHaveBeenCalledWith ( [
184194 anyMarkerMatcher ,
185195 anyMarkerMatcher ,
186196 ] ) ;
187- } ) ) ;
197+ } ) ;
188198
189- it ( 'updates Google Maps Markers in the Marker Clusterer' , fakeAsync ( ( ) => {
199+ it ( 'updates Google Maps Markers in the Marker Clusterer' , async ( ) => {
190200 fixture . detectChanges ( ) ;
191- flush ( ) ;
201+ await fixture . whenStable ( ) ;
202+ await wait ( 50 ) ;
192203
193204 expect ( markerClustererSpy . addMarkers ) . toHaveBeenCalledWith ( [
194205 anyMarkerMatcher ,
@@ -198,7 +209,8 @@ describe('DeprecatedMapMarkerClusterer', () => {
198209 fixture . componentInstance . state = 'state2' ;
199210 fixture . changeDetectorRef . markForCheck ( ) ;
200211 fixture . detectChanges ( ) ;
201- flush ( ) ;
212+ await fixture . whenStable ( ) ;
213+ await wait ( 50 ) ;
202214
203215 expect ( markerClustererSpy . addMarkers ) . toHaveBeenCalledWith ( [ anyMarkerMatcher ] , true ) ;
204216 expect ( markerClustererSpy . removeMarkers ) . toHaveBeenCalledWith ( [ anyMarkerMatcher ] , true ) ;
@@ -207,19 +219,21 @@ describe('DeprecatedMapMarkerClusterer', () => {
207219 fixture . componentInstance . state = 'state0' ;
208220 fixture . changeDetectorRef . markForCheck ( ) ;
209221 fixture . detectChanges ( ) ;
210- flush ( ) ;
222+ await fixture . whenStable ( ) ;
223+ await wait ( 50 ) ;
211224
212225 expect ( markerClustererSpy . addMarkers ) . toHaveBeenCalledWith ( [ ] , true ) ;
213226 expect ( markerClustererSpy . removeMarkers ) . toHaveBeenCalledWith (
214227 [ anyMarkerMatcher , anyMarkerMatcher ] ,
215228 true ,
216229 ) ;
217230 expect ( markerClustererSpy . repaint ) . toHaveBeenCalledTimes ( 2 ) ;
218- } ) ) ;
231+ } ) ;
219232
220- it ( 'exposes marker clusterer methods' , fakeAsync ( ( ) => {
233+ it ( 'exposes marker clusterer methods' , async ( ) => {
221234 fixture . detectChanges ( ) ;
222- flush ( ) ;
235+ await fixture . whenStable ( ) ;
236+ await wait ( 50 ) ;
223237 const markerClustererComponent = fixture . componentInstance . markerClusterer ;
224238
225239 markerClustererComponent . fitMapToMarkers ( 5 ) ;
@@ -286,11 +300,12 @@ describe('DeprecatedMapMarkerClusterer', () => {
286300
287301 markerClustererSpy . getZoomOnClick . and . returnValue ( true ) ;
288302 expect ( markerClustererComponent . getZoomOnClick ( ) ) . toBe ( true ) ;
289- } ) ) ;
303+ } ) ;
290304
291- it ( 'initializes marker clusterer event handlers' , fakeAsync ( ( ) => {
305+ it ( 'initializes marker clusterer event handlers' , async ( ) => {
292306 fixture . detectChanges ( ) ;
293- flush ( ) ;
307+ await fixture . whenStable ( ) ;
308+ await wait ( 50 ) ;
294309
295310 expect ( markerClustererSpy . addListener ) . toHaveBeenCalledWith (
296311 'clusteringbegin' ,
@@ -301,9 +316,13 @@ describe('DeprecatedMapMarkerClusterer', () => {
301316 jasmine . any ( Function ) ,
302317 ) ;
303318 expect ( markerClustererSpy . addListener ) . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
304- } ) ) ;
319+ } ) ;
305320} ) ;
306321
322+ function wait ( milliseconds : number ) {
323+ return new Promise ( resolve => setTimeout ( resolve , milliseconds ) ) ;
324+ }
325+
307326@Component ( {
308327 selector : 'test-app' ,
309328 template : `
0 commit comments