[英]Spec Has No Expectations error on Angular 2 templateUrl
I have a angular 2 Component MyComp 我有一个角度2组件MyComp
@Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES]
})
This is my spec. 这是我的规格。
it('should work', injectAsync([TestComponentBuilder], (tcb) => {
return tcb.createAsync(MyComp).then((fixture) => {
fixture.detectChanges();
expect(1+ 1).toEqual(2);
});
}));
When i execute the tests its giving me an error 当我执行测试时,它给我一个错误
Can't bind to 'ngForOf' since it isn't a known native property
The actual code works, but its only the tests that are failing, 实际的代码有效,但只有失败的测试,
Update : Spec works if i replace templateUrl with template. 更新:如果我用template替换templateUrl,Spec可以工作。 ie if i just try with
即如果我只是尝试
template: <h1>Fake</h1> <ul> <li *ngFor="#item of items"> </li> </ul>
模板:
<h1>Fake</h1> <ul> <li *ngFor="#item of items"> </li> </ul>
Interested to know if anyone has tested components with templateUrl with angular 2.0 beta version. 有兴趣知道是否有人使用angular 2.0 beta版的templateUrl测试了组件。
Thanks ! 谢谢 !
You should add ngFor
or CORE_DIRECTIVES
to the component directives : 您应该将
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 { /* ... */ }
or 要么
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.