A StackBlitz has been set up with the karma/jasmine loader for you to view test pass/fail results.
The application is functioning correctly.
All my tests are expected to pass without any issues, but I am encountering an unusual error when using a mockservice instead of the actual service in the createspyobject
.
component.ts
getReportFunc(): void {
this.reportService.getReport(this.urn).subscribe(selectedReport => {
this.model = selectedReport;
});
}
This method makes a simple call to a service to retrieve "getReport". A test will be added to ensure that the report has been retrieved, but currently facing a roadblock due to this issue.
spec.ts
describe("SearchComponent", () => {
let component: SearchComponent;
let fixture: ComponentFixture<SearchComponent>;
let mockReportService;
beforeEach(async(() => {
mockReportService = jasmine.createSpyObj(['getReport']);
TestBed.configureTestingModule({
declarations: [SearchComponent],
providers: [
//ReportService,
{ provide: ReportService, useValue: mockReportService },
...
The problem lies in using
{ provide: ReportService, useValue: mockReportService }
, whereas just using ReportService
works fine but restricts running one of the tests. The aim is to create a spy object with mockReportService = jasmine.createSpyObj(['getReport']);
.
An error message stating
TypeError: Cannot read property 'subscribe' of undefined
can be seen in the StackBlitz. Assistance in resolving this issue to successfully run with a mockservice for testing the getReport subscribe function would be greatly appreciated.