Angular 使用Typescript的集成测试不会将回调调用到subscribe中
我正在编写一个集成测试来检查后端的API 这项服务是:Angular 使用Typescript的集成测试不会将回调调用到subscribe中,angular,typescript,integration-testing,Angular,Typescript,Integration Testing,我正在编写一个集成测试来检查后端的API 这项服务是: 导出类服务{ 检查(详细信息:凭证、成功块、错误块){ 让localString=“changeAuthenticationCredentialAPI/v2/authenticationCredential/check”; 让url=BASE\u url\u SERVER+localString; 让body={details}; 让成功=(数据)=>{ 让_authorization=data.headers[“authorizatio
导出类服务{
检查(详细信息:凭证、成功块、错误块){
让localString=“changeAuthenticationCredentialAPI/v2/authenticationCredential/check”;
让url=BASE\u url\u SERVER+localString;
让body={details};
让成功=(数据)=>{
让_authorization=data.headers[“authorization”];
让_clientID=data.body.relatedParty[0].id[0].value;
let _token:token={};
_token.token=\u授权;
_token.clientId=\u clientId;
successBlock(_令牌);
}
this.post(success、errorBlock、url、body);
}
handleErrorSync(错误){
试一试{
返回Observable.throw(JSON.parse(error._body));
}捕获(e){
返回可观察的抛出(错误体);
}
}
post(成功、错误、url、正文){
常量选项={
标头:新的HttpHeaders(标头_请求)
};
let call=this.http.post(url、正文、选项).catch(this.handleErrorSync);
this.makeCall(调用、成功、错误);
}
makeCall(调用、成功、错误){
call.flatMap(
(结果)=>{
如果(此响应OK(结果)){
可观察的回报(结果);
}否则{
误差(结果);
返回可观察。抛出(结果);
}
}
).订阅(
(结果)=>{
成功(结果);},
(错误)=>{
这个.popuperor(err);
错误(err);
}
);
}
}
最后,我发现问题与以下事实有关:我正在将HttpClientModule和HttpClientTestingModule用于测试床配置的导入,并且不知何故,它破坏了集成测试。
移除HttpClientTestingModule就成功了
describe("authentication-credential-service.spec", () => {
let backend : Service
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule
],
providers: [
Service,
{ provide: ToastController, useClass: class { ToastController = jasmine.createSpy("ToastController"); } },
{ provide: ModalController, useClass: class { ModalController = jasmine.createSpy("ModalController"); } },
FileTransfer,
File
]
});
backend = TestBed.get(Service);
}));
it("should be created", inject([Service], (service: Service) => {
expect(service).toBeTruthy();
}));
describe("check", () => {
it( "should answer 200 with the right token", async(inject([Service], (service:Service) => {
let credential: Credential = {};
credential.credentialType = "password";
credential.usernameText = "user";
credential.passwordText = "therightpassword";
let _result : Token
let successBlock = ( (data) => {
_result = data
expect(data).toBeDefined();
} );
let errorBlock = (error) => {
expect(false).toBeTruthy();
};
service.check(
credential,
successBlock,
errorBlock
);
})));
});
})
你到底在茉莉花的什么地方打电话?(你说得对……确定标题)