@@ -5,7 +5,10 @@ import {
5
5
dispatchMouseEvent ,
6
6
patchElementFocus ,
7
7
} 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' ;
9
12
import { ComponentFixture , fakeAsync , inject , TestBed , tick } from '@angular/core/testing' ;
10
13
import { By } from '@angular/platform-browser' ;
11
14
import { FocusMonitor , FocusOrigin , TOUCH_BUFFER_MS } from './focus-monitor' ;
@@ -395,7 +398,6 @@ describe('cdkMonitorFocus', () => {
395
398
describe ( 'FocusMonitor observable stream' , ( ) => {
396
399
let fixture : ComponentFixture < MonitoredElementRequiringChangeDetection > ;
397
400
let buttonElement : HTMLElement ;
398
- let focusMonitor : FocusMonitor ;
399
401
400
402
beforeEach ( ( ) => {
401
403
TestBed . configureTestingModule ( {
@@ -406,23 +408,20 @@ describe('FocusMonitor observable stream', () => {
406
408
} ) . compileComponents ( ) ;
407
409
} ) ;
408
410
409
- beforeEach ( inject ( [ FocusMonitor ] , ( fm : FocusMonitor ) => {
411
+ beforeEach ( ( ) => {
410
412
fixture = TestBed . createComponent ( MonitoredElementRequiringChangeDetection ) ;
411
413
fixture . detectChanges ( ) ;
412
-
413
414
buttonElement = fixture . componentInstance . button . nativeElement ;
414
- focusMonitor = fm ;
415
-
416
415
patchElementFocus ( buttonElement ) ;
417
- } ) ) ;
416
+ } ) ;
418
417
419
- it ( 'should emit inside the NgZone' , ( ) => {
418
+ it ( 'should emit inside the NgZone' , fakeAsync ( ( ) => {
420
419
fixture . detectChanges ( ) ;
421
420
expect ( buttonElement . innerText ) . toBe ( '' ) ;
422
421
buttonElement . focus ( ) ;
423
422
fixture . detectChanges ( ) ;
424
423
expect ( buttonElement . innerText ) . toBe ( 'program' ) ;
425
- } ) ;
424
+ } ) ) ;
426
425
} ) ;
427
426
428
427
@@ -452,16 +451,21 @@ class ComplexComponentWithMonitorElementFocus {}
452
451
class ComplexComponentWithMonitorSubtreeFocus { }
453
452
454
453
@Component ( {
455
- template : `<button #b>{{origin}}</button>`
454
+ template : `<button #b>{{origin}}</button>` ,
455
+ changeDetection : ChangeDetectionStrategy . OnPush
456
456
} )
457
457
class MonitoredElementRequiringChangeDetection {
458
458
@ViewChild ( 'b' ) button : ElementRef ;
459
459
origin : string ;
460
460
461
- constructor ( private _focusMonitor : FocusMonitor ) { }
461
+ constructor ( private _focusMonitor : FocusMonitor ,
462
+ private _changeDetectorRef : ChangeDetectorRef ) { }
462
463
463
464
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
+ } ) ;
465
469
}
466
470
467
471
ngOnDestroy ( ) {
0 commit comments