Skip to content

Commit 73f6c16

Browse files
committed
test(multiple): Update test initializer to provide zoneless by default
This commit uses the zoneless provier for all tests by default. Tests which failed have either been updated to be compatible or have been opted out. Note that tests which were opted out does not mean the components are incompatible with zoneless, but likely that the tests rely on the zone provider in some way. Opt outs require the private `ZONELESS_ENABLED` token set to `false` in the providers manually because there is a check that will throw an error when both zoneless and zone providers are used. This should likely be fixed in the framework code to make it easier for test suites to do what we're doing here: use zoneless for all tests by default and temporarily use zones for tests that need it until there is time to migrate them.
1 parent 37958ef commit 73f6c16

File tree

149 files changed

+1164
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1164
-534
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656
},
5757
"version": "18.1.0-next.0",
5858
"dependencies": {
59-
"@angular/animations": "^18.0.0-rc.0",
60-
"@angular/common": "^18.0.0-rc.0",
61-
"@angular/compiler": "^18.0.0-rc.0",
62-
"@angular/core": "^18.0.0-rc.0",
63-
"@angular/forms": "^18.0.0-rc.0",
64-
"@angular/platform-browser": "^18.0.0-rc.0",
59+
"@angular/animations": "^18.0.0-rc.1",
60+
"@angular/common": "^18.0.0-rc.1",
61+
"@angular/compiler": "^18.0.0-rc.1",
62+
"@angular/core": "^18.0.0-rc.1",
63+
"@angular/forms": "^18.0.0-rc.1",
64+
"@angular/platform-browser": "^18.0.0-rc.1",
6565
"@types/google.maps": "^3.54.10",
6666
"@types/youtube": "^0.0.50",
6767
"rxjs": "^6.6.7",
@@ -76,12 +76,12 @@
7676
"@angular/bazel": "https://github.com/angular/bazel-builds.git#bac9c1abe1e6ac1801fbbccb53353a1ed7126469",
7777
"@angular/build-tooling": "https://github.com/angular/dev-infra-private-build-tooling-builds.git#a11e93b01708684827af3873e9232b437c209237",
7878
"@angular/cli": "^18.0.0-rc.0",
79-
"@angular/compiler-cli": "^18.0.0-rc.0",
80-
"@angular/localize": "^18.0.0-rc.0",
79+
"@angular/compiler-cli": "^18.0.0-rc.1",
80+
"@angular/localize": "^18.0.0-rc.1",
8181
"@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#36946be4df61f6549ae3829c026022e47674eae2",
82-
"@angular/platform-browser-dynamic": "^18.0.0-rc.0",
83-
"@angular/platform-server": "^18.0.0-rc.0",
84-
"@angular/router": "^18.0.0-rc.0",
82+
"@angular/platform-browser-dynamic": "^18.0.0-rc.1",
83+
"@angular/platform-server": "^18.0.0-rc.1",
84+
"@angular/router": "^18.0.0-rc.1",
8585
"@babel/core": "^7.16.12",
8686
"@babel/helper-explode-assignable-expression": "^7.18.6",
8787
"@babel/helper-string-parser": "^7.22.5",

src/cdk-experimental/combobox/combobox.spec.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import {Component, DebugElement, ElementRef, ViewChild} from '@angular/core';
1+
import {
2+
Component,
3+
ɵZONELESS_ENABLED,
4+
DebugElement,
5+
ElementRef,
6+
ViewChild,
7+
signal,
8+
} from '@angular/core';
29
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
310
import {By} from '@angular/platform-browser';
411
import {CdkComboboxModule} from './combobox-module';
@@ -25,6 +32,7 @@ describe('Combobox', () => {
2532

2633
beforeEach(waitForAsync(() => {
2734
TestBed.configureTestingModule({
35+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}],
2836
imports: [CdkComboboxModule, ComboboxToggle],
2937
}).compileComponents();
3038
}));
@@ -83,7 +91,7 @@ describe('Combobox', () => {
8391

8492
it('should toggle focus upon toggling the panel', () => {
8593
comboboxElement.focus();
86-
testComponent.actions = 'toggle';
94+
testComponent.actions.set('toggle');
8795
fixture.detectChanges();
8896

8997
expect(document.activeElement).toEqual(comboboxElement);
@@ -209,7 +217,7 @@ describe('Combobox', () => {
209217
});
210218

211219
it('should coerce actions separated by space', () => {
212-
testComponent.actions = 'focus click';
220+
testComponent.actions.set('focus click');
213221
fixture.detectChanges();
214222

215223
const openActions = comboboxInstance.openActions;
@@ -219,7 +227,7 @@ describe('Combobox', () => {
219227
});
220228

221229
it('should coerce actions separated by comma', () => {
222-
testComponent.actions = 'focus,click,downKey';
230+
testComponent.actions.set('focus,click,downKey');
223231
fixture.detectChanges();
224232

225233
const openActions = comboboxInstance.openActions;
@@ -230,7 +238,7 @@ describe('Combobox', () => {
230238
});
231239

232240
it('should coerce actions separated by commas and spaces', () => {
233-
testComponent.actions = 'focus click,downKey';
241+
testComponent.actions.set('focus click,downKey');
234242
fixture.detectChanges();
235243

236244
const openActions = comboboxInstance.openActions;
@@ -241,10 +249,10 @@ describe('Combobox', () => {
241249
});
242250

243251
it('should throw error when given invalid open action', () => {
244-
expect(() => {
245-
testComponent.actions = 'invalidAction';
246-
fixture.detectChanges();
247-
}).toThrow();
252+
const errorSpy = spyOn(console, 'error');
253+
testComponent.actions.set('invalidAction');
254+
fixture.detectChanges();
255+
expect(errorSpy).toHaveBeenCalled();
248256
});
249257
});
250258

@@ -274,7 +282,7 @@ describe('Combobox', () => {
274282
});
275283

276284
it('should open panel with focus open action', () => {
277-
testComponent.actions = 'focus';
285+
testComponent.actions.set('focus');
278286
fixture.detectChanges();
279287

280288
expect(comboboxInstance.isOpen()).toBeFalse();
@@ -286,7 +294,7 @@ describe('Combobox', () => {
286294
});
287295

288296
it('should open panel with click open action', () => {
289-
testComponent.actions = 'click';
297+
testComponent.actions.set('click');
290298
fixture.detectChanges();
291299

292300
expect(comboboxInstance.isOpen()).toBeFalse();
@@ -298,7 +306,7 @@ describe('Combobox', () => {
298306
});
299307

300308
it('should open panel with downKey open action', () => {
301-
testComponent.actions = 'downKey';
309+
testComponent.actions.set('downKey');
302310
fixture.detectChanges();
303311

304312
expect(comboboxInstance.isOpen()).toBeFalse();
@@ -310,7 +318,7 @@ describe('Combobox', () => {
310318
});
311319

312320
it('should toggle panel with toggle open action', () => {
313-
testComponent.actions = 'toggle';
321+
testComponent.actions.set('toggle');
314322
fixture.detectChanges();
315323

316324
expect(comboboxInstance.isOpen()).toBeFalse();
@@ -327,7 +335,7 @@ describe('Combobox', () => {
327335
});
328336

329337
it('should close panel on escape key', () => {
330-
testComponent.actions = 'click';
338+
testComponent.actions.set('click');
331339
fixture.detectChanges();
332340

333341
expect(comboboxInstance.isOpen()).toBeFalse();
@@ -344,7 +352,7 @@ describe('Combobox', () => {
344352
});
345353

346354
it('should handle multiple open actions', () => {
347-
testComponent.actions = 'click downKey';
355+
testComponent.actions.set('click downKey');
348356
fixture.detectChanges();
349357

350358
expect(comboboxInstance.isOpen()).toBeFalse();
@@ -371,7 +379,7 @@ describe('Combobox', () => {
371379
template: `
372380
<button cdkCombobox #toggleCombobox="cdkCombobox" class="example-combobox"
373381
[cdkComboboxTriggerFor]="panel"
374-
[openActions]="actions">
382+
[openActions]="actions()">
375383
No Value
376384
</button>
377385
<div id="other-content"></div>
@@ -388,5 +396,5 @@ describe('Combobox', () => {
388396
class ComboboxToggle {
389397
@ViewChild('input') inputElement: ElementRef<HTMLInputElement>;
390398

391-
actions: string = 'click';
399+
actions = signal('click');
392400
}

src/cdk-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import {LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW, TAB} from '@angular/cdk/k
33
import {CdkTableModule} from '@angular/cdk/table';
44
import {dispatchKeyboardEvent} from '@angular/cdk/testing/private';
55
import {CommonModule} from '@angular/common';
6-
import {Component, Directive, ElementRef, ViewChild} from '@angular/core';
6+
import {
7+
Component,
8+
Directive,
9+
ElementRef,
10+
ɵZONELESS_ENABLED,
11+
ViewChild,
12+
provideZoneChangeDetection,
13+
} from '@angular/core';
714
import {ComponentFixture, fakeAsync, flush, TestBed, tick} from '@angular/core/testing';
815
import {FormsModule, NgForm} from '@angular/forms';
916
import {BidiModule, Direction} from '@angular/cdk/bidi';
@@ -382,6 +389,7 @@ describe('CDK Popover Edit', () => {
382389
beforeEach(fakeAsync(() => {
383390
TestBed.configureTestingModule({
384391
imports: [CdkTableModule, CdkPopoverEditModule, CommonModule, FormsModule, BidiModule],
392+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}, provideZoneChangeDetection()],
385393
declarations: [componentClass],
386394
}).compileComponents();
387395
fixture = TestBed.createComponent<BaseTestComponent>(componentClass);

src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ describe('CdkVirtualScrollViewport', () => {
4949
it('should throw if maxBufferPx is less than minBufferPx', fakeAsync(() => {
5050
testComponent.minBufferPx = 100;
5151
testComponent.maxBufferPx = 99;
52-
expect(() => finishInit(fixture)).toThrow();
52+
const errorSpy = spyOn(console, 'error');
53+
finishInit(fixture);
54+
expect(errorSpy).toHaveBeenCalled();
5355
}));
5456

5557
// TODO(mmalerba): Add test that it corrects the initial render if it didn't render enough,

src/cdk-experimental/table-scroll-container/table-scroll-container.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {CollectionViewer, DataSource} from '@angular/cdk/collections';
2-
import {Component, Type, ViewChild} from '@angular/core';
2+
import {Component, Type, ViewChild, ɵZONELESS_ENABLED} from '@angular/core';
33
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
44
import {BehaviorSubject, combineLatest} from 'rxjs';
55
import {map} from 'rxjs/operators';
@@ -23,6 +23,7 @@ describe('CdkTableScrollContainer', () => {
2323
declarations: any[] = [],
2424
): ComponentFixture<T> {
2525
TestBed.configureTestingModule({
26+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}],
2627
imports: [CdkTableModule, CdkTableScrollContainerModule, componentType, ...declarations],
2728
}).compileComponents();
2829

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import {
88
dispatchEvent,
99
} from '../../testing/private';
1010
import {DOCUMENT} from '@angular/common';
11-
import {Component, NgZone, ViewChild} from '@angular/core';
11+
import {
12+
Component,
13+
NgZone,
14+
ViewChild,
15+
provideZoneChangeDetection,
16+
ɵZONELESS_ENABLED,
17+
} from '@angular/core';
1218
import {ComponentFixture, fakeAsync, flush, inject, TestBed, tick} from '@angular/core/testing';
1319
import {By} from '@angular/platform-browser';
1420
import {Platform} from '@angular/cdk/platform';
@@ -826,7 +832,11 @@ describe('FocusMonitor observable stream', () => {
826832
fakePlatform = {isBrowser: true} as Platform;
827833
TestBed.configureTestingModule({
828834
imports: [A11yModule, PlainButton],
829-
providers: [{provide: Platform, useValue: fakePlatform}],
835+
providers: [
836+
{provide: Platform, useValue: fakePlatform},
837+
{provide: ɵZONELESS_ENABLED, useValue: false},
838+
provideZoneChangeDetection(),
839+
],
830840
}).compileComponents();
831841
});
832842

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
TemplateRef,
66
ViewContainerRef,
77
ViewEncapsulation,
8+
ɵZONELESS_ENABLED,
89
} from '@angular/core';
910
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
1011
import {PortalModule, CdkPortalOutlet, TemplatePortal} from '@angular/cdk/portal';
@@ -14,6 +15,7 @@ import {By} from '@angular/platform-browser';
1415
describe('FocusTrap', () => {
1516
beforeEach(waitForAsync(() => {
1617
TestBed.configureTestingModule({
18+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}],
1719
imports: [
1820
A11yModule,
1921
PortalModule,

src/cdk/a11y/live-announcer/live-announcer.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {MutationObserverFactory} from '@angular/cdk/observers';
22
import {Overlay} from '@angular/cdk/overlay';
33
import {ComponentPortal} from '@angular/cdk/portal';
4-
import {Component} from '@angular/core';
4+
import {Component, ɵZONELESS_ENABLED} from '@angular/core';
55
import {ComponentFixture, fakeAsync, flush, inject, TestBed, tick} from '@angular/core/testing';
66
import {By} from '@angular/platform-browser';
77
import {A11yModule} from '../index';
@@ -21,6 +21,7 @@ describe('LiveAnnouncer', () => {
2121
describe('with default element', () => {
2222
beforeEach(() =>
2323
TestBed.configureTestingModule({
24+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}],
2425
imports: [A11yModule, TestApp, TestModal],
2526
}),
2627
);
@@ -127,6 +128,7 @@ describe('LiveAnnouncer', () => {
127128
fixture.destroy();
128129

129130
TestBed.resetTestingModule().configureTestingModule({
131+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}],
130132
imports: [A11yModule],
131133
});
132134

@@ -225,7 +227,10 @@ describe('LiveAnnouncer', () => {
225227

226228
return TestBed.configureTestingModule({
227229
imports: [A11yModule, TestApp],
228-
providers: [{provide: LIVE_ANNOUNCER_ELEMENT_TOKEN, useValue: customLiveElement}],
230+
providers: [
231+
{provide: ɵZONELESS_ENABLED, useValue: false},
232+
{provide: LIVE_ANNOUNCER_ELEMENT_TOKEN, useValue: customLiveElement},
233+
],
229234
});
230235
});
231236

@@ -249,6 +254,7 @@ describe('LiveAnnouncer', () => {
249254
return TestBed.configureTestingModule({
250255
imports: [A11yModule, TestApp],
251256
providers: [
257+
{provide: ɵZONELESS_ENABLED, useValue: false},
252258
{
253259
provide: LIVE_ANNOUNCER_DEFAULT_OPTIONS,
254260
useValue: {
@@ -297,6 +303,7 @@ describe('CdkAriaLive', () => {
297303
TestBed.configureTestingModule({
298304
imports: [A11yModule, DivWithCdkAriaLive],
299305
providers: [
306+
{provide: ɵZONELESS_ENABLED, useValue: false},
300307
{
301308
provide: MutationObserverFactory,
302309
useValue: {

src/cdk/bidi/directionality.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {waitForAsync, fakeAsync, TestBed} from '@angular/core/testing';
2-
import {Component, ViewChild} from '@angular/core';
2+
import {Component, ViewChild, signal} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {BidiModule, Directionality, Dir, Direction, DIR_DOCUMENT} from './index';
55

@@ -102,7 +102,7 @@ describe('Directionality', () => {
102102
expect(injectedDirectionality.value).toBe('rtl');
103103
expect(fixture.componentInstance.changeCount).toBe(0);
104104

105-
fixture.componentInstance.direction = 'ltr';
105+
fixture.componentInstance.direction.set('ltr');
106106

107107
fixture.detectChanges();
108108

@@ -129,7 +129,7 @@ describe('Directionality', () => {
129129
fixture.detectChanges();
130130
expect(fixture.componentInstance.dir.value).toBe('rtl');
131131

132-
fixture.componentInstance.direction = 'not-valid';
132+
fixture.componentInstance.direction.set('not-valid');
133133
fixture.detectChanges();
134134
expect(fixture.componentInstance.dir.value).toBe('ltr');
135135
});
@@ -170,7 +170,7 @@ class InjectsDirectionality {
170170

171171
@Component({
172172
template: `
173-
<div [dir]="direction" (dirChange)="changeCount = changeCount + 1">
173+
<div [dir]="direction()" (dirChange)="changeCount = changeCount + 1">
174174
<injects-directionality></injects-directionality>
175175
</div>
176176
`,
@@ -179,7 +179,7 @@ class InjectsDirectionality {
179179
})
180180
class ElementWithDir {
181181
@ViewChild(Dir) dir: Dir;
182-
direction = 'rtl';
182+
direction = signal('rtl');
183183
changeCount = 0;
184184
}
185185

src/cdk/clipboard/copy-to-clipboard.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component} from '@angular/core';
1+
import {Component, ɵZONELESS_ENABLED} from '@angular/core';
22
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
33

44
import {Clipboard} from './clipboard';
@@ -30,6 +30,7 @@ describe('CdkCopyToClipboard', () => {
3030
beforeEach(fakeAsync(() => {
3131
TestBed.configureTestingModule({
3232
imports: [ClipboardModule, CopyToClipboardHost],
33+
providers: [{provide: ɵZONELESS_ENABLED, useValue: false}],
3334
});
3435

3536
TestBed.compileComponents();

0 commit comments

Comments
 (0)