angular/angular · error · Error

Cannot set autoDetect to false with zoneless change detectio

Error message

Cannot set autoDetect to false with zoneless change detection.

What it means

Error "Cannot set autoDetect to false with zoneless change detection." thrown in angular/angular.

Source

Thrown at packages/core/testing/src/component_fixture.ts:204

  /**
   * Set whether the fixture should autodetect changes.
   *
   * Also runs detectChanges once so that any existing change is detected.
   *
   * @param autoDetect Whether to autodetect changes. By default, `true`.
   * @deprecated For `autoDetect: true`, use `autoDetectChanges()`.
   * We have not seen a use-case for `autoDetect: false` but `changeDetectorRef.detach()` is a close equivalent.
   */
  autoDetectChanges(autoDetect: boolean): void;
  /**
   * Enables automatically synchronizing the view, as it would in an application.
   *
   * Also runs detectChanges once so that any existing change is detected.
   */
  autoDetectChanges(): void;
  autoDetectChanges(autoDetect = true): void {
    if (!autoDetect && this.zonelessEnabled) {
      throw new Error('Cannot set autoDetect to false with zoneless change detection.');
    }
    if (this._noZoneOptionIsSet && !this.zonelessEnabled) {
      throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set.');
    }

    if (autoDetect) {
      this._testAppRef.autoDetectTestViews.add(this.componentRef.hostView);
    } else {
      this._testAppRef.autoDetectTestViews.delete(this.componentRef.hostView);
    }

    this.autoDetect = autoDetect;
    this.detectChanges();
  }

  /**
   * Return whether the fixture is currently stable or has async tasks that have not been completed
   * yet.

View on GitHub (pinned to 51cb07e980)

Solutions

  1. Do not disable autoDetect with zoneless change detection; rely on signal-driven updates.

When it happens

Trigger: Thrown at packages/core/testing/src/component_fixture.ts:204 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of angular/angular@51cb07e980 (2026-08-22). Data as JSON: /api/errors/f62003015001981a. Report an issue: GitHub.