Skip to content

Aot test : Signal viewQueries broken when component is overriden #63188

@JeanMeche

Description

@JeanMeche

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

While debugging some tests on adev I stumbled upon this :

import {  Component,  provideZonelessChangeDetection,  viewChild,} from '@angular/core';
import { TestBed } from '@angular/core/testing';

@Component({
  template: `<button #resizer></button>`,
})
export class Tutorial {
  readonly resizer = viewChild('resizer');
}

describe('Tutorial', () => {
  it('should create', () => {
    TestBed.configureTestingModule({
      providers: [provideZonelessChangeDetection()],
    });

    // Comment to pass the test
    TestBed.overrideComponent(Tutorial, {});

    const fixture = TestBed.createComponent(Tutorial);
    fixture.detectChanges();
    expect(fixture.componentInstance.resizer()).toBeDefined();
  });
});

AOT + overriding a component breaks signal view queries.

Edit: It only affects signal view queries, the decorator ones are fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimearea: testingIssues related to Angular testing features, such as TestBed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions