I'm new to testing. I have a service and a spec file that when run I get the following error:
Error: Can't resolve all parameters for DashboardService: (?). error properties: Object({ ngSyntaxError: true })
The spec file looks like this:
import { TestBed } from '@angular/core/testing';
import { DashboardService } from './dashboard.service';
import { ApiService } from './../api.service';
describe('The Dashboard Service', () => {
beforeEach(() => {
TestBed.configureTestingModule({ providers: [DashboardService, ApiService] });
});
it('should be created', () => {
const service: DashboardService = TestBed.get(DashboardService);
expect(service).toBeTruthy();
});
});
The service looks like this so far:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService } from './../api.service';
import { Organization } from '../../models/organization';
@Injectable({
providedIn: ApiService
})
export class DashboardService {
constructor(private api: ApiService) {}
getPrograms(id: number): Observable<any> {
let url = '/apiurl' + id;
return this.api.get<Organization>(url);
}
}
So I guess the error is because of the dependencies to the service file but after reading the Angular documentation I'm still not sure of how to let Angular know about these dependencies. How do I structured the spec file to read dependencies correctly?