|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import {TestBed} from '../testing';
|
10 |
| -import {filter, tap} from 'rxjs/operators'; |
| 10 | +import {filter} from 'rxjs/operators'; |
11 | 11 |
|
12 | 12 | import {EventEmitter} from '../src/event_emitter';
|
13 |
| -import {ApplicationRef} from '../public_api'; |
| 13 | +import {ApplicationRef, NgZone} from '../public_api'; |
14 | 14 |
|
15 | 15 | describe('EventEmitter', () => {
|
16 | 16 | let emitter: EventEmitter<number>;
|
@@ -206,6 +206,21 @@ describe('EventEmitter', () => {
|
206 | 206 | expect(emitValue!).toEqual(1);
|
207 | 207 | });
|
208 | 208 |
|
| 209 | + it('should not prevent app from becoming stable if subscriber throws an error', async () => { |
| 210 | + const logs: string[] = []; |
| 211 | + const ngZone = TestBed.inject(NgZone); |
| 212 | + const appRef = TestBed.inject(ApplicationRef); |
| 213 | + appRef.isStable.subscribe((isStable) => logs.push(`isStable=${isStable}`)); |
| 214 | + const emitter = TestBed.runInInjectionContext(() => new EventEmitter<number>(true)); |
| 215 | + emitter.subscribe(() => { |
| 216 | + throw new Error('Given this is some TypeError...'); |
| 217 | + }); |
| 218 | + // Emit inside the Angular zone so that the error is not captured by Jasmine in `afterAll`. |
| 219 | + ngZone.run(() => emitter.emit(1)); |
| 220 | + await appRef.whenStable(); |
| 221 | + expect(logs).toEqual(['isStable=true', 'isStable=false', 'isStable=true']); |
| 222 | + }); |
| 223 | + |
209 | 224 | // TODO: vsavkin: add tests cases
|
210 | 225 | // should call dispose on the subscription if generator returns {done:true}
|
211 | 226 | // should call dispose on the subscription on throw
|
|
0 commit comments