Skip to content

Commit 985aa18

Browse files
committed
fix(@angular-devkit/build-angular): conditionally provide Zone.js change detection in the built-in test main file
Prior to this change Zone.js change detection provider was never added. Closes #32047
1 parent 385165c commit 985aa18

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/angular_devkit/build_angular/src/builders/karma/browser_builder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,20 @@ async function initializeBrowser(
149149
return [karma, (await webpackConfigurationTransformer?.(config)) ?? config];
150150
}
151151

152-
function getBuiltInMainFile(includeZoneProvider = false): string {
152+
function getBuiltInMainFile(): string {
153153
const content = Buffer.from(
154154
`
155155
import { provideZoneChangeDetection, ɵcompileNgModuleDefs as compileNgModuleDefs } from '@angular/core';
156156
import { getTestBed } from '@angular/core/testing';
157157
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
158158
159+
const providers = [];
160+
if (typeof window.Zone !== 'undefined') {
161+
providers.push(provideZoneChangeDetection());
162+
}
163+
159164
export class TestModule {}
160-
compileNgModuleDefs(TestModule, {providers: [${includeZoneProvider ? 'provideZoneChangeDetection()' : ''}]});
165+
compileNgModuleDefs(TestModule, {providers});
161166
162167
// Initialize the Angular testing environment.
163168
getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), {

0 commit comments

Comments
 (0)