Angular Karma测试中没有存储供应商

Angular Karma测试中没有存储供应商,angular,jasmine,ionic4,karma-jasmine,Angular,Jasmine,Ionic4,Karma Jasmine,我多次尝试运行这些测试。我真的不确定,似乎也找不出它为什么错了。我正在我的Ionic应用程序上使用存储模块,当尝试将其添加到单元测试时,我得到以下错误。我很迷路,所以任何帮助都会很感激的 NullInjectorError:StaticInjectorError(DynamicTestModule)[AuthService->Storage]: StaticInjectorError(平台:核心)[AuthService->Storage]: NullInjectorError:没有存储的提供程

我多次尝试运行这些测试。我真的不确定,似乎也找不出它为什么错了。我正在我的Ionic应用程序上使用存储模块,当尝试将其添加到单元测试时,我得到以下错误。我很迷路,所以任何帮助都会很感激的

NullInjectorError:StaticInjectorError(DynamicTestModule)[AuthService->Storage]: StaticInjectorError(平台:核心)[AuthService->Storage]: NullInjectorError:没有存储的提供程序

从'@angular/core/testing'导入{TestBed,fakeAsync,tick,inject};
进口{
HttpClientTestingModule,
HttpTestingController,
}来自“@angular/common/http/testing”;
从“/auth.service”导入{AuthService};
从“@angular/common/http”导入{HttpErrorResponse};
从'@ionic/Storage'导入{IonicStorageModule};
从'rxjs'导入{of};
描述('AuthServiceService',()=>{
let服务:AuthService;
设httpTestingController:httpTestingController;
在每个之前(()=>{
TestBed.configureTestingModule({
供应商:[
授权服务
],
进口:[
HttpClientTestingModule,
IonicStorageModule.forRoot()的
],
});
httpTestingController=TestBed.get(httpTestingController);
service=TestBed.get(AuthService);
});
它('应该创建',()=>{
expect(service.toBeTruthy();
});
它('应该运行HandleError 1次',fakeAsync(()=>{
spyOn(服务,'handleError')。和.callThrough();
handleError(新的HttpErrorResponse({error:'error'}));
勾选();
期望(服务。处理错误)。已被催收时间(1);
}));
它('应该调用登录1次',注入([IonicStorageModule],(存储:IonicStorageModule)=>{
const serviceSpy=spyOn(服务为AuthService,'login');
service.login(“”);
expect(serviceSpy.calls.count()).toBe(1);
}));
它('应该调用注销1次',()=>{
const serviceSpy=spyOn(服务为AuthService,'logout');
服务。注销(“”);
expect(serviceSpy.calls.count()).toBe(1);
});
它('应该调用getAuthenticationDetails 1次',()=>{
const serviceSpy=spyOn(服务为AuthService,'getAuthenticationDetails')。和.callThrough();
service.getAuthenticationDetails();
预期(serviceSpy)。已被催收时间(1);
});
它('应该调用setIsAuthenticated 1次',()=>{
const serviceSpy=spyOn(服务为AuthService,'setIsAuthenticated')。和.callThrough();
setIsAuthenticated(true,“myaccount”);
预期(serviceSpy)。已被催收时间(1);
});
它('当类型为ros时,应调用setIsAuthenticated 1次',()=>{
const serviceSpy=spyOn(服务为AuthService,'setIsAuthenticated')。和.callThrough();
setIsAuthenticated(null,'ros');
预期(serviceSpy)。已被催收时间(1);
});
它('应该调用登录1次',()=>{
const serviceSpy=spyOn(服务为AuthService,'login')。和.callThrough();
service.login(“”);
预期(serviceSpy)。已被催收时间(1);
});
它('应该调用注销1次',()=>{
const serviceSpy=spyOn(服务为AuthService,'logout')。和.callThrough();
服务。注销(“”);
预期(serviceSpy)。已被催收时间(1);
});
它('抛出404错误',()=>{
service.login(“”).subscribe(
data=>fail('本应失败,出现404错误'),
(错误:HttpErrorResponse)=>{
expect(error.status).toEqual(404);
expect(error.error).toContain('404error');
}
);
});
它('抛出401错误',()=>{
service.login(“”).subscribe(
data=>fail('本应失败,出现401错误'),
(错误:HttpErrorResponse)=>{
expect(error.status).toEqual(401);
expect(error.message).toContain('401error');
}
);
});
});

也许这有帮助:我的朋友,如果我能给你买一杯啤酒或任何生命饮料,我肯定会的。在学习因果报应/茉莉花的过程中,我还有一段路要走,它仍然让我感到困惑。但是谢谢你。如果你愿意回答,我会接受的。不客气。祝你好运,玩得开心。我们都还在学习;-)只是出于兴趣,如果我有一个页面使用了使用存储的Auth服务,我应该将存储注入到我的页面测试中吗?好的,看来我还有一段路要走。我有一个使用Auth的sign。但这是关于没有存储提供商的身份验证登录。身份验证服务测试现在可以工作了,不过问题是基于此的,所以谢谢:)