@@ -5,7 +5,10 @@ import {
55 dispatchMouseEvent ,
66 patchElementFocus ,
77} from '@angular/cdk/testing' ;
8- import { Component , ElementRef , ViewChild } from '@angular/core' ;
8+ import {
9+ ChangeDetectionStrategy , ChangeDetectorRef , Component , ElementRef ,
10+ ViewChild
11+ } from '@angular/core' ;
912import { ComponentFixture , fakeAsync , inject , TestBed , tick } from '@angular/core/testing' ;
1013import { By } from '@angular/platform-browser' ;
1114import { FocusMonitor , FocusOrigin , TOUCH_BUFFER_MS } from './focus-monitor' ;
@@ -395,7 +398,6 @@ describe('cdkMonitorFocus', () => {
395398describe ( 'FocusMonitor observable stream' , ( ) => {
396399 let fixture : ComponentFixture < MonitoredElementRequiringChangeDetection > ;
397400 let buttonElement : HTMLElement ;
398- let focusMonitor : FocusMonitor ;
399401
400402 beforeEach ( ( ) => {
401403 TestBed . configureTestingModule ( {
@@ -406,23 +408,20 @@ describe('FocusMonitor observable stream', () => {
406408 } ) . compileComponents ( ) ;
407409 } ) ;
408410
409- beforeEach ( inject ( [ FocusMonitor ] , ( fm : FocusMonitor ) => {
411+ beforeEach ( ( ) => {
410412 fixture = TestBed . createComponent ( MonitoredElementRequiringChangeDetection ) ;
411413 fixture . detectChanges ( ) ;
412-
413414 buttonElement = fixture . componentInstance . button . nativeElement ;
414- focusMonitor = fm ;
415-
416415 patchElementFocus ( buttonElement ) ;
417- } ) ) ;
416+ } ) ;
418417
419- it ( 'should emit inside the NgZone' , ( ) => {
418+ it ( 'should emit inside the NgZone' , fakeAsync ( ( ) => {
420419 fixture . detectChanges ( ) ;
421420 expect ( buttonElement . innerText ) . toBe ( '' ) ;
422421 buttonElement . focus ( ) ;
423422 fixture . detectChanges ( ) ;
424423 expect ( buttonElement . innerText ) . toBe ( 'program' ) ;
425- } ) ;
424+ } ) ) ;
426425} ) ;
427426
428427
@@ -452,16 +451,21 @@ class ComplexComponentWithMonitorElementFocus {}
452451class ComplexComponentWithMonitorSubtreeFocus { }
453452
454453@Component ( {
455- template : `<button #b>{{origin}}</button>`
454+ template : `<button #b>{{origin}}</button>` ,
455+ changeDetection : ChangeDetectionStrategy . OnPush
456456} )
457457class MonitoredElementRequiringChangeDetection {
458458 @ViewChild ( 'b' ) button : ElementRef ;
459459 origin : string ;
460460
461- constructor ( private _focusMonitor : FocusMonitor ) { }
461+ constructor ( private _focusMonitor : FocusMonitor ,
462+ private _changeDetectorRef : ChangeDetectorRef ) { }
462463
463464 ngOnInit ( ) {
464- this . _focusMonitor . monitor ( this . button . nativeElement ) . subscribe ( o => this . origin = o || '' ) ;
465+ this . _focusMonitor . monitor ( this . button . nativeElement ) . subscribe ( o => {
466+ this . origin = o || '' ;
467+ this . _changeDetectorRef . markForCheck ( ) ;
468+ } ) ;
465469 }
466470
467471 ngOnDestroy ( ) {
0 commit comments