Skip to content

bug(TestbedHarnessEnvironment): After updating from Karma/Jasmine to Vitest using TestbedHarnessEnvironment.loader(fixture) in spec file throws Expected to be running in 'ProxyZone', but it was not found error when running ng test #32542

@roesselman

Description

@roesselman

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

v20.2.2

Description

Hello, I updated my project where I use material from angular version 20.2.2 to version 21.0.5. After updating Angular I configured it to work with Vitest when i run ng test. It all works fine except when I do the following line const loader = TestbedHarnessEnvironment.loader(fixture); in my tests.

When that line is in my spec file and I run ng test I get the error Error: Expected to be running in 'ProxyZone', but it was not found..

How can I solve this so my tests that use TestbedHarnessEnvironment.loader will run again?

Reproduction

I tried to make a stackblitz, but wasn't able to get ng serve with vitest to work.

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-peyuzeyh?file=src%2Fapp%2Fapp.component.spec.ts
Steps to reproduce:

  1. Install angular 21
  2. Install Material
  3. npm i -D vitest jsdom
  4. configure test in angular.json
  5. Add mat-form-field to html of component
  6. Add spec file to component that uses TestbedHarnessEnvironment.loader
  7. Run ng test

Expected Behavior

Test should work, not throw error and pass

Actual Behavior

ng test throws error: Error: Expected to be running in 'ProxyZone', but it was not found.

Environment

  • Angular: 21.0.5
  • CDK/Material: 21.0.3
  • Browser(s): Chrome
  • Operating System: Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue needs to be triaged by the team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions