@@ -60,5 +60,61 @@ describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
6060 const { result } = await harness . executeOnce ( ) ;
6161 expect ( result ?. success ) . toBeTrue ( ) ;
6262 } ) ;
63+
64+ it ( 'should work with providers that inject services requiring JIT compilation' , async ( ) => {
65+ // This test reproduces the issue from https://github.com/angular/angular-cli/issues/31993
66+ // where using providersFile with a service that injects Router causes JIT compilation errors
67+ await harness . writeFiles ( {
68+ 'src/test.service.ts' : `
69+ import { Injectable, inject } from '@angular/core';
70+ import { Router } from '@angular/router';
71+
72+ @Injectable({ providedIn: 'root' })
73+ export class TestService {
74+ router = inject(Router);
75+ }
76+ ` ,
77+ 'src/test.providers.ts' : `
78+ import { TestService } from './test.service';
79+ export default [TestService];
80+ ` ,
81+ 'src/app/app.component.spec.ts' : `
82+ import { TestBed } from '@angular/core/testing';
83+ import { AppComponent } from './app.component';
84+ import { TestService } from '../test.service';
85+ import { describe, expect, it } from 'vitest';
86+
87+ describe('AppComponent', () => {
88+ it('should create the app and inject TestService', () => {
89+ TestBed.configureTestingModule({
90+ declarations: [AppComponent],
91+ });
92+ const fixture = TestBed.createComponent(AppComponent);
93+ const app = fixture.componentInstance;
94+ const testService = TestBed.inject(TestService);
95+ expect(app).toBeTruthy();
96+ expect(testService).toBeTruthy();
97+ expect(testService.router).toBeTruthy();
98+ });
99+ });
100+ ` ,
101+ } ) ;
102+ await harness . modifyFile ( 'src/tsconfig.spec.json' , ( content ) => {
103+ const tsConfig = JSON . parse ( content ) ;
104+ tsConfig . files ??= [ ] ;
105+ tsConfig . files . push ( 'test.service.ts' , 'test.providers.ts' ) ;
106+
107+ return JSON . stringify ( tsConfig ) ;
108+ } ) ;
109+
110+ harness . useTarget ( 'test' , {
111+ ...BASE_OPTIONS ,
112+ providersFile : 'src/test.providers.ts' ,
113+ } ) ;
114+
115+ const { result } = await harness . executeOnce ( ) ;
116+
117+ expect ( result ?. success ) . toBeTrue ( ) ;
118+ } ) ;
63119 } ) ;
64120} ) ;
0 commit comments