在Angular 7中,如果出现Karma错误:“无法解析WebStorageService的所有参数:(?)”,通常是因为在测试中没有正确配置WebStorageService依赖项。
解决方法如下:
import { WebStorageService } from 'angular-webstorage-service';
providers: [
WebStorageService,
]
如果WebStorageService有其他依赖项,请确保在providers数组中添加这些依赖项。
如果WebStorageService是通过DI(依赖注入)获取的,请确保在测试文件中正确设置依赖注入。例如:
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{ provide: WebStorageService, useClass: MyCustomWebStorageService },
],
});
});
请注意,MyCustomWebStorageService是您自己定义的替代WebStorageService的类。
通过以上步骤,您应该能够解决“无法解析WebStorageService的所有参数:(?)”错误,并成功运行测试。