Skip to content

Guide for asyncFake references src/test.ts with Angular CLI, which is not generated with v21 #66029

@lazarljubenovic

Description

@lazarljubenovic

Describe the problem that you experienced

The documentation says:

To use fakeAsync() functionality, you must import zone.js/testing in your test setup file. If you created your project with the Angular CLI, zone-testing is already imported in src/test.ts.

But a project created with Angular CLI does not even have a src/test.ts file, let alone an import to any zone-testing.

Also, zone-testing is probably referring to the older import 'zone.js/dist/zone-testing', which is now properly exposed as zone.js/testing. zone-testing is mentioned once again on that page and might need updating to zone.js/testing, or an explanation of what it refers to.

Enter the URL of the topic with the problem

https://angular.dev/guide/testing/components-scenarios#async-test-with-fakeasync:~:text=link-,To%20use,.,-The%20following%20test

Describe what you were looking for in the documentation

I was reading about how fakeAsync works and what are the prerequisites for using it.

Describe the actions that led you to experience the problem

I am migrating a project from a custom set up with Angular 19 with tests in Karma to using Angular CLI with Angular 21 with tests in Vitest (ouch indeed) and this error pops up in some tests.

Expected to be running in 'ProxyZone', but it was not found.

Apparently it's related to fakeAsync not being set up properly. I ran ng new on the side to see what a clean project will generate now (so I can mimic it in my setup), and despite it using @angular/build:unit-test with the vitest runner, there's no src/test.ts file generated anywhere. So I assume the documentation here is wrong.

Describe what you want to experience that would fix the problem

It should probably either say that CLI handles this under the hood, or that we need to manually add "setupFiles" in angular.json to include it.

Add a screenshot if that helps illustrate the problem

No response

If this problem caused an exception or error, please paste it here


If the problem is browser-specific, please specify the device, OS, browser, and version


Provide any additional information here in as much as detail as you can


Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docsRelated to the documentationarea: 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