[英]Angular test service is undefined
import { TestBed } from '@angular/core/testing';
import { CallsClient, CallVm } from './web-api-client';
import { ConsultationDataService } from './consultation-data.service';
import { Observable, of } from 'rxjs';
describe('ConsultationDataService', () => {
let service: ConsultationDataService;
let callsClientSpy: jasmine.SpyObj<CallsClient>;
beforeEach(() => {
const spy = jasmine.createSpyObj('CallsClient', ['get']);
spy.get.and.returnValue(of(new CallVm()));
TestBed.configureTestingModule({
providers: [
ConsultationDataService,
{ provide: CallsClient, useClass: spy }
]
})
service = TestBed.inject(ConsultationDataService);
callsClientSpy = TestBed.inject(CallsClient) as jasmine.SpyObj<CallsClient>;
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
当我的测试运行时,服务未定义?! 我究竟做错了什么? ConsultationDataService 只依赖于 CallsClient!
Mauro Aguilar 指出了打字错误! 用值代替用例!
TestBed.configureTestingModule({
providers: [
ConsultationDataService,
{ provide: CallsClient, useValue: spy }
]
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.