Skip to content

Commit de01346

Browse files
committed
test: rewrite tests that test zone.js implementation details
1 parent 3a48d1f commit de01346

File tree

6 files changed

+352
-662
lines changed

6 files changed

+352
-662
lines changed

src/cdk/a11y/focus-monitor/focus-monitor.spec.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {TAB} from '@angular/cdk/keycodes';
22
import {Platform} from '@angular/cdk/platform';
33
import {DOCUMENT} from '@angular/common';
4-
import {Component, ViewChild} from '@angular/core';
4+
import {Component, ViewChild, provideZoneChangeDetection} from '@angular/core';
55
import {ComponentFixture, TestBed, fakeAsync, flush, inject, tick} from '@angular/core/testing';
66
import {By} from '@angular/platform-browser';
77
import {
@@ -34,6 +34,7 @@ describe('FocusMonitor', () => {
3434
TestBed.configureTestingModule({
3535
imports: [A11yModule, PlainButton],
3636
providers: [
37+
provideZoneChangeDetection(),
3738
{
3839
provide: DOCUMENT,
3940
useFactory: () => {
@@ -899,6 +900,25 @@ describe('FocusMonitor input label detection', () => {
899900
}));
900901
});
901902

903+
describe('cdkMonitorFocus with change detection counter', () => {
904+
beforeEach(() => {
905+
TestBed.configureTestingModule({
906+
imports: [A11yModule, ButtonWithCDCounter],
907+
providers: [{provide: Platform, useValue: {isBrowser: true}}],
908+
}).compileComponents();
909+
});
910+
911+
it('should detect changes caused by focus change', async () => {
912+
const fixture = TestBed.createComponent(ButtonWithCDCounter);
913+
fixture.autoDetectChanges();
914+
const buttonElement = fixture.nativeElement.querySelector('button');
915+
buttonElement.focus();
916+
await fixture.whenStable();
917+
const focusChangeCounter = fixture.nativeElement.querySelector('.focus-change-counter');
918+
expect(focusChangeCounter.innerText).toBe('1');
919+
});
920+
});
921+
902922
@Component({
903923
template: `<div class="parent"><button>focus me!</button></div>`,
904924
standalone: true,
@@ -961,3 +981,15 @@ class CheckboxWithLabel {}
961981
class ExportedFocusMonitor {
962982
@ViewChild('exportedDir') exportedDirRef: CdkMonitorFocus;
963983
}
984+
985+
@Component({
986+
template: `
987+
<button cdkMonitorElementFocus (cdkFocusChange)="focusChangeCount = focusChangeCount + 1"></button>
988+
<div class="focus-change-counter">{{focusChangeCount}}</div>
989+
`,
990+
standalone: true,
991+
imports: [A11yModule],
992+
})
993+
class ButtonWithCDCounter {
994+
focusChangeCount = 0;
995+
}

src/cdk/a11y/focus-monitor/focus-monitor.zone.spec.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)