我正在开发Angular应用程序,并且正忙于使用Jasmine在Angular中进行一些单元测试。
我有这段代码:
toc-entry
我有这个单元测试:
/** Gets the case by id */
getCase(id: number, spinnerMessage?: string) {
return this.http.get<CaseBaseModel>(`${this.api}/${id}`, spinnerMessage).pipe(map(c => new CaseBaseModel(c)));
}
但是在这段代码中:
it('should get case by id', () => {
const spy = spyOn(service, 'getCase').and.callThrough();
// tslint:disable-next-line:no-commented-code
const mockData = new CaseBaseModel({
id: 100001075,
dateSubmitted: '',
owner: caseOwnerEnum.caseManager,
reference: 'ksjhkjshdf',
status: caseStatusEnum.submitted,
type: caseTypeEnum.revisionRequest,
});
service.getCase(mockData.id, 'spinner').subscribe(r => expect(r).toEqual(100001075));
expect(spy).toHaveBeenCalledWith(mockData.id, 'spinner');
// tslint:disable-next-line:no-commented-code
// expect(mockData.id).toEqual(100001075);
});
这段代码:
/** Gets the case by id */
getCase(id: number, spinnerMessage?: string) {
return this.http.get<CaseBaseModel>(`${this.api}/${id}`, spinnerMessage).pipe(map(c => new CaseBaseModel(c)));
}
仍然是红色。
那怎么解决呢?
谢谢。
这是CodeBaseModel类:
c => new CaseBaseModel(c)));