Skip to content

Commit f182886

Browse files
atscottthePunderWoman
authored andcommitted
refactor(core): Disallow autoDetectChanges(false) in zoneless (angular#61430)
This removes the ability to use `autoDetectChanges(false)` when `provideZonelessChangeDetection` is used. PR Close angular#61430
1 parent ef0f1a4 commit f182886

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/core/test/component_fixture_spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ describe('ComponentFixture with zoneless', () => {
634634
expect(() => fixture.detectChanges()).toThrowError(/ExpressionChanged/);
635635
});
636636

637-
it('runs change detection when autoDetect is false', () => {
637+
it('disallows autoDetect: false', () => {
638638
@Component({
639639
template: '{{thing()}}',
640640
})
@@ -643,9 +643,6 @@ describe('ComponentFixture with zoneless', () => {
643643
}
644644

645645
const fixture = TestBed.createComponent(App);
646-
fixture.autoDetectChanges(false);
647-
fixture.componentInstance.thing.set(2);
648-
fixture.detectChanges();
649-
expect(fixture.nativeElement.innerText).toBe('2');
646+
expect(() => fixture.autoDetectChanges(false)).toThrow();
650647
});
651648
});

packages/core/testing/src/component_fixture.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ export class ComponentFixture<T> {
196196
*/
197197
autoDetectChanges(): void;
198198
autoDetectChanges(autoDetect = true): void {
199+
if (!autoDetect && this.zonelessEnabled) {
200+
throw new Error('Cannot set autoDetect to false with zoneless change detection.');
201+
}
199202
if (this._noZoneOptionIsSet && !this.zonelessEnabled) {
200203
throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set.');
201204
}

0 commit comments

Comments
 (0)