【发布时间】:2017-09-27 12:35:38
【问题描述】:
我想在运行之前将数据注入DeviceMarkerComponent:
let component: DeviceMarkerComponent;
let fixture: ComponentFixture<DeviceMarkerComponent>;
...
fixture = TestBed.createComponent(DeviceMarkerComponent);
component = fixture.componentInstance;
DeviceMarkerComponent 使用ngOnInit 中的变量,如果不初始化变量,我无法创建组件。 NgOnInit 在调用 TestBed.CreateComponent 时会触发并导致错误,因此我必须设置这些变量或修改我正在测试的代码:(
【问题讨论】:
-
知道它抛出了什么错误会很有帮助。 DeviceMarkerComponent 在其构造函数中是否存在您未提供的依赖项?
-
我添加了图片
-
没关系,我已经解决了,我会在晚上添加解决方案
标签: angular jasmine karma-runner