我正在使用Angular 2 Final,并使用TestBed进行单元测试
使用" overrideDirective "时出现问题似乎正在调用实际指令,因为我收到错误" 没有配置提供商!"被替换的MyDirective取决于。
组件视图
<div>
<input myDirective>
// some more logic etc...
</div>
替换指令
@Directive({
selector: "myDirective"
})
class MyDirective{
constructor(
private config: Config
) {
}
}
规范文件
@Component({
template: "<my-component></my-component>"
})
class TestComponent{
}
@Directive({
selector: "fake"
})
class FakeDirective {
}
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
MyComponent,
MyDirective,
TestComponent,
FakeDirective
]
});
});
beforeEach(async(() => {
TestBed
.overrideDirective(MyDirective, FakeDirective)
.compileComponents();
fixture = TestBed.createComponent(TestComponent);
}));
有人遇到过这个问题,并设法解决了吗?
由于