I have a large Angular App that works fine. (v20 if it matters)
I recently added a new service to my App.Component, and now I'm getting the following error. ONLY in Karma, the service works as expected when running my app locally, and deployed to Production.
And this same service passes unit tests in it's own SPEC file, it just caused the App.Component.spec.ts to blow up. I'm sure it's due to some kind of DI issue, but I don't know what.
./src/app/app.component.ts:1206:0-92 - Error: Module not found: Error: Can't resolve './services/mapOffers/mapOffers.component.js' in 'c:\Source\Project\src\app'
I really have no idea how to even trouble shoot this since it works perfect outside of Karma. The 'MapOffers' service does nothing more than an API call to get a set of data. But I'm mocking (see below) so it's not even doing anything.
Here's the top of App.Component: (note, I'm not even consuming the service here. Just injecting it is causing this). Keep in mind, it works perfect in normal mode, and it's even in production this way working perfect.
import { MapOffers } from './services/mapOffers/mapOffers.component.js';
//#endregion
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
standalone: false
})
export class AppComponent implements OnInit {
private _router = inject(Router);
private _mapOffers = inject(MapOffers);
The constructor for MapOffers is as follows. This module is in App.Module It's also mocked in App.Component
@Injectable({
providedIn: "root",
})
export class MapOffers {
In the spec file, I am mocking it as follows:
describe(AppComponent.name, () => {
beforeEach(async () => {
const mockMapsffers: Partial<MapOffers> = {};
const mockHttpHandler: Partial<HttpHandler> = {};
const mockHttpClient: Partial<HttpClient> = {};
await TestBed.configureTestingModule({
imports: [
RouterModule.forRoot([])
],
providers: [
{ provide: MapOffers, useValue: mockMapOffers},
{ provide: HttpHandler, useValue: mockHttpHandler},
{ provide: HttpClient, useValue: mockHttpClient},
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
});