-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Open
Labels
needs triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When testing click behaviors using Angular's TestHarness (e.g., MatButtonHarness.click()) in a Vitest environment with jsdom, the test fails with the following error:
TypeError: Failed to construct 'PointerEvent': member view is not of type Window.
This issue is caused by the presence of the view: window property in the MouseEvent options, which is not supported in jsdom. This is a known limitation in Vitest (see vitest-dev/vitest#4685).
A temporary solution is to configure Vitest to use the vmThreads pool in the defineConfig:
export default defineConfig({
test: {
pool: 'vmThreads',
}
});However, this workaround is not ideal, as it is unclear, non-obvious, and may not be recommended for all use cases.
Reproduction
Steps to reproduce:
ng new whateverusing @angular/cli@21ng add @angular/material- Import
MatButtoninAppcomponent - Add the following method
protected sayHello(): void { alert('Hello World!'); }
- Add matButton element in template
<button matButton="filled" (click)="sayHello()">Click Me!</button>
- Add test case
it('should open alert with hello world when click me button is clicked', async () => { const fixture = TestBed.createComponent(App); const loader = TestbedHarnessEnvironment.loader(fixture); vi.stubGlobal('alert', vi.fn()); const button = await loader.getHarness( MatButtonHarness.with({ text: 'Click Me!', }) ); await button.click(); expect(alert).toHaveBeenCalledWith('Hello World!'); });
- Run
ng test - Observe the test failure with the above error.
Expected Behavior
Should not fail
Actual Behavior
TypeError: Failed to construct 'PointerEvent': member view is not of type Window.
Environment
- Angular: 21.0.0
- CDK/Material: 21.0.0
- Node: 24.11.1
- Operating System: Windows 11
glenstaes
Metadata
Metadata
Assignees
Labels
needs triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team