I'm having this snippet of code in a service
readonly timezones = resource({
loader: () => {
return firstValueFrom(this.getAll()).catch(() => {
return [];
});
}
});
readonly #apiService = inject(ApiService);
public getAll(): Observable<TimezoneWithFacilitiesResponse[]> {
return this.#apiService.get<TimezoneWithFacilitiesResponse[]>(`${this.apiUrl}/GetAll`);
}
When i try to use the HttpTestingController I always end up with an error in the test
let httpMock: HttpTestingController;
let service: TimezonesService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
makeEnvironmentProviders([
{
provide: AppSettings,
useValue: settingsMock
}
]),
provideHttpClient(),
provideHttpClientTesting(),
ApiService,
TimezonesService
]
});
httpMock = TestBed.inject(HttpTestingController);
service = TestBed.inject(TimezonesService);
});
afterEach(() => {
httpMock.verify();
});
it('should get all time zones', waitForAsync(() => {
const expectedResponse = timezonesMock as TimezoneWithFacilitiesResponse[];
// service.timezones.value();
service.getAll().subscribe((response) => {
expect(response).toEqual(expectedResponse);
});
const testUrl = `${settingsMock.url}/${service.apiUrl}/GetAll`;
const request = httpMock.expectOne({
method: HttpMethod.GET,
url: testUrl
});
request.flush(expectedResponse);
}));
});
I end up with one open request. How to deal with this?