|
1 | 1 | import {TestBed, ComponentFixture} from '@angular/core/testing';
|
2 |
| -import {Component, DebugElement, Provider, Type} from '@angular/core'; |
| 2 | +import {ApplicationRef, Component, DebugElement, Provider, Type} from '@angular/core'; |
3 | 3 | import {By} from '@angular/platform-browser';
|
4 | 4 | import {dispatchFakeEvent} from '../../cdk/testing/private';
|
5 | 5 | import {MatProgressBarModule, MAT_PROGRESS_BAR_DEFAULT_OPTIONS} from './index';
|
@@ -231,14 +231,16 @@ describe('MDC-based MatProgressBar', () => {
|
231 | 231 |
|
232 | 232 | it('should trigger output event on primary value bar animation end', () => {
|
233 | 233 | fixture.detectChanges();
|
234 |
| - spyOn(progressComponent.animationEnd, 'next'); |
| 234 | + |
| 235 | + const animationEndSpy = jasmine.createSpy(); |
| 236 | + progressComponent.animationEnd.subscribe(animationEndSpy); |
235 | 237 |
|
236 | 238 | progressComponent.value = 40;
|
237 |
| - expect(progressComponent.animationEnd.next).not.toHaveBeenCalled(); |
| 239 | + expect(animationEndSpy).not.toHaveBeenCalled(); |
238 | 240 |
|
239 | 241 | // On animation end, output should be emitted.
|
240 | 242 | dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
|
241 |
| - expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40}); |
| 243 | + expect(animationEndSpy).toHaveBeenCalledWith({value: 40}); |
242 | 244 | });
|
243 | 245 | });
|
244 | 246 |
|
@@ -267,27 +269,56 @@ describe('MDC-based MatProgressBar', () => {
|
267 | 269 |
|
268 | 270 | it('should trigger output event on primary value bar animation end', () => {
|
269 | 271 | fixture.detectChanges();
|
270 |
| - spyOn(progressComponent.animationEnd, 'next'); |
| 272 | + |
| 273 | + const animationEndSpy = jasmine.createSpy(); |
| 274 | + progressComponent.animationEnd.subscribe(animationEndSpy); |
271 | 275 |
|
272 | 276 | progressComponent.value = 40;
|
273 |
| - expect(progressComponent.animationEnd.next).not.toHaveBeenCalled(); |
| 277 | + expect(animationEndSpy).not.toHaveBeenCalled(); |
274 | 278 |
|
275 | 279 | // On animation end, output should be emitted.
|
276 | 280 | dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
|
277 |
| - expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40}); |
| 281 | + expect(animationEndSpy).toHaveBeenCalledWith({value: 40}); |
278 | 282 | });
|
279 | 283 |
|
280 | 284 | it('should trigger output event with value not bufferValue', () => {
|
281 | 285 | fixture.detectChanges();
|
282 |
| - spyOn(progressComponent.animationEnd, 'next'); |
| 286 | + |
| 287 | + const animationEndSpy = jasmine.createSpy(); |
| 288 | + progressComponent.animationEnd.subscribe(animationEndSpy); |
283 | 289 |
|
284 | 290 | progressComponent.value = 40;
|
285 | 291 | progressComponent.bufferValue = 70;
|
286 |
| - expect(progressComponent.animationEnd.next).not.toHaveBeenCalled(); |
| 292 | + expect(animationEndSpy).not.toHaveBeenCalled(); |
287 | 293 |
|
288 | 294 | // On animation end, output should be emitted.
|
289 | 295 | dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
|
290 |
| - expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({value: 40}); |
| 296 | + expect(animationEndSpy).toHaveBeenCalledWith({value: 40}); |
| 297 | + }); |
| 298 | + |
| 299 | + it('should not run change detection if there are no `animationEnd` observers', () => { |
| 300 | + fixture.detectChanges(); |
| 301 | + |
| 302 | + const animationEndSpy = jasmine.createSpy(); |
| 303 | + const appRef = TestBed.inject(ApplicationRef); |
| 304 | + spyOn(appRef, 'tick'); |
| 305 | + |
| 306 | + progressComponent.value = 30; |
| 307 | + progressComponent.bufferValue = 60; |
| 308 | + // On animation end, output should be emitted. |
| 309 | + dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend'); |
| 310 | + |
| 311 | + expect(appRef.tick).not.toHaveBeenCalled(); |
| 312 | + |
| 313 | + progressComponent.animationEnd.subscribe(animationEndSpy); |
| 314 | + |
| 315 | + progressComponent.value = 40; |
| 316 | + progressComponent.bufferValue = 70; |
| 317 | + // On animation end, output should be emitted. |
| 318 | + dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend'); |
| 319 | + |
| 320 | + expect(appRef.tick).toHaveBeenCalled(); |
| 321 | + expect(animationEndSpy).toHaveBeenCalledWith({value: 40}); |
291 | 322 | });
|
292 | 323 | });
|
293 | 324 | });
|
|
0 commit comments