A. *_*ius 5 unit-testing angular
我正在使用 Angular 2 Final,并使用 TestBed 进行单元测试
我在使用“ overrideDirective ”时遇到问题,似乎正在调用实际指令,因为我收到错误“ No provider for Config! ” 被替换的 MyDirective 依赖于该错误。
组件视图
<div>
<input myDirective>
// some more logic etc...
</div>
Run Code Online (Sandbox Code Playgroud)
替换指令
@Directive({
selector: "myDirective"
})
class MyDirective{
constructor(
private config: Config
) {
}
}
Run Code Online (Sandbox Code Playgroud)
规格文件
@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);
}));
Run Code Online (Sandbox Code Playgroud)
请问有人遇到过这个问题并解决了吗?
谢谢