Cześć.
Mam problem z tworzeniem jednego testu:
describe('StatusComponent', () => {
let component: StatusComponent;
let fixture: ComponentFixture<StatusComponent>;
let taskService: jasmine.SpyObj<TaskService>;
taskService = jasmine.createSpyObj('TaskService', ['getStatusOfProject']);
taskService.getStatusOfProject.and.returnValue(taskRound); // tu mam problem
let taskRound: TaskRound[] = [
{
'id': 'id1',
'idTask': 'idtask31',
'task' : 'zadanie',
'usersTransfer': 'user_transfer_test',
'createdAt': 2020,
'status' : 1
},
];
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [ StatusComponent, FilterTablePipe, StatusPipe ],
providers: [
{ provide: TaskService, useFactory: () => spyOnClass(TaskService) },
]
})
.compileComponents();
}));
});
A tak wygląda mój TaskService:
getStatusOfProject(way) {
return this.http.get<TaskRound[]>(`${environment.apiUrl}/api/transfer/show/` + way);
}
Problem mam w miejscu zwrócenia zawartości przez
taskService.getStatusOfProject.and.returnValue(taskService);
Otóż ciągle dostaje błąd typu :
error TS2345: Argument of type 'TaskRound[]' is not assignable to parameter of type 'Observable<TaskRound[]>'.
Type 'TaskRound[]' is missing the following properties from type 'Observable<TaskRound[]>': _isScalar, source, operator, lift, and 5 more.
28 taskService.getStatusOfProject.and.returnValue(taskRound);
error TS2448: Block-scoped variable 'taskRound' used before its declaration.
Kombinuje na różne sposoby aby to jakoś zamokować , ale nie kumam jak to zrobić.
Z góry dziękuje za pomoc.