[英]Spec Has No Expectations error on Angular 2 templateUrl
我有一个角度2组件MyComp
@Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES]
})
这是我的规格。
it('should work', injectAsync([TestComponentBuilder], (tcb) => {
return tcb.createAsync(MyComp).then((fixture) => {
fixture.detectChanges();
expect(1+ 1).toEqual(2);
});
}));
当我执行测试时,它给我一个错误
Can't bind to 'ngForOf' since it isn't a known native property
实际的代码有效,但只有失败的测试,
更新:如果我用template替换templateUrl,Spec可以工作。 即如果我只是尝试
模板: <h1>Fake</h1> <ul> <li *ngFor="#item of items"> </li> </ul>
有兴趣知道是否有人使用angular 2.0 beta版的templateUrl测试了组件。
谢谢 !
您应该将ngFor
或CORE_DIRECTIVES
添加到组件指令中 :
import { CORE_DIRECTIVES } from 'angular2/common';
@Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES] // <- HERE!!!
})
export class MyForm { /* ... */ }
要么
import { NgFor } from 'angular2/common';
@Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES, NgFor] // <- HERE!!!
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.