type here
Im using functional interceptor in angular 17, this works with ng serve but when trying run unit test i get this error:
An error was thrown in afterAll
Uncaught ReferenceError: Cannot access 'urlInterceptor' before initialization
ReferenceError: Cannot access 'urlInterceptor' before initialization
at Module.urlInterceptor (http://localhost:9876/_karma_webpack_/main.js:398:61)
...
My testing file: todo-item.component.spec.ts
describe('component', () => {
beforeEach(() => {
TestBed.configureTestingModule({
...
providers: [
TodosService,
provideHttpClient(withInterceptors([urlInterceptor])),
provideHttpClientTesting()
],
...
})
.compileComponents();
...
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
I try deleting all other .spec files, providing HttpClientModule in tradicional way, changing the import order in .spec file and app.config.ts file, but nothing works.