Please provide the environment you discovered this bug in.
Below is a minimal example of a test setup that throws NG0951 when fastCompile: true is enabled:
import {
Component,
ElementRef,
computed,
viewChild,
} from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { expect, it } from 'vitest';
@Component({
selector: 'app-test-component',
template: `
<div #trigger>origin</div>
<p>width: {{ panelWidth() }}</p>
`,
})
class TestComponent {
readonly trigger = viewChild.required<ElementRef<HTMLElement>>('trigger');
readonly clientWidth = computed(
() => this.trigger().nativeElement.clientWidth,
);
}
it('should create the app', () => {
const fixture = TestBed.createComponent(TestComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
Which area/package is the issue in?
vite-plugin-angular
Description
Tests that are passing with fastCompile: false and using viewChild.required are throwing an NG0951 error.
Please provide the exception or error you saw
Error: NG0951: Child query result is required but not available. Find more at https://v21.angular.dev/errors/NG0951
Other information
I cannot reproduce the error in Stackblitz. I am posting it here anyway understanding that Stackblitz behaves differently due to its restricted environment.
I would be willing to submit a PR to fix this issue
Please provide the environment you discovered this bug in.
Below is a minimal example of a test setup that throws NG0951 when
fastCompile: trueis enabled:Which area/package is the issue in?
vite-plugin-angular
Description
Tests that are passing with
fastCompile: falseand usingviewChild.requiredare throwing an NG0951 error.Please provide the exception or error you saw
Other information
I cannot reproduce the error in Stackblitz. I am posting it here anyway understanding that Stackblitz behaves differently due to its restricted environment.
I would be willing to submit a PR to fix this issue