|
8 | 8 |
|
9 | 9 |
|
10 | 10 | import {CommonModule} from '@angular/common';
|
11 |
| -import {ApplicationRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactoryResolver, ComponentRef, Directive, DoCheck, EmbeddedViewRef, ErrorHandler, Input, NgModule, OnInit, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core'; |
12 |
| -import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 11 | +import {ApplicationRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactoryResolver, ComponentRef, Directive, DoCheck, EmbeddedViewRef, ErrorHandler, EventEmitter, Input, NgModule, OnInit, Output, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core'; |
| 12 | +import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; |
13 | 13 | import {expect} from '@angular/platform-browser/testing/src/matchers';
|
14 | 14 | import {ivyEnabled} from '@angular/private/testing';
|
15 | 15 | import {BehaviorSubject} from 'rxjs';
|
@@ -461,6 +461,41 @@ describe('change detection', () => {
|
461 | 461 | expect(comp.doCheckCount).toEqual(2);
|
462 | 462 | expect(fixture.nativeElement.textContent.trim()).toEqual('3 - 2 - Nancy');
|
463 | 463 | });
|
| 464 | + |
| 465 | + it('should check parent OnPush components when child directive on a template emits event', |
| 466 | + fakeAsync(() => { |
| 467 | + @Directive({ |
| 468 | + selector: '[emitter]', |
| 469 | + }) |
| 470 | + class Emitter { |
| 471 | + @Output() event = new EventEmitter<string>(); |
| 472 | + |
| 473 | + ngOnInit() { |
| 474 | + setTimeout(() => { |
| 475 | + this.event.emit('new message'); |
| 476 | + }); |
| 477 | + } |
| 478 | + } |
| 479 | + |
| 480 | + |
| 481 | + @Component({ |
| 482 | + selector: 'my-app', |
| 483 | + template: '{{message}} <ng-template emitter (event)="message = $event"></ng-template>', |
| 484 | + changeDetection: ChangeDetectionStrategy.OnPush |
| 485 | + }) |
| 486 | + class MyApp { |
| 487 | + message = 'initial message'; |
| 488 | + } |
| 489 | + |
| 490 | + const fixture = TestBed.configureTestingModule({declarations: [MyApp, Emitter]}) |
| 491 | + .createComponent(MyApp); |
| 492 | + fixture.detectChanges(); |
| 493 | + |
| 494 | + expect(fixture.nativeElement.textContent.trim()).toEqual('initial message'); |
| 495 | + tick(); |
| 496 | + fixture.detectChanges(); |
| 497 | + expect(fixture.nativeElement.textContent.trim()).toEqual('new message'); |
| 498 | + })); |
464 | 499 | });
|
465 | 500 |
|
466 | 501 | describe('ChangeDetectorRef', () => {
|
|
0 commit comments