Specular在Angular 2 templateUrl上没有期望错误

时间:2016-01-02 21:21:13

标签: jasmine angular

我有一个有角度的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

实际代码有效,但它只是失败的测试,

更新 如果我用模板替换templateUrl,则规范有效。 即如果我只是尝试

模板:<h1>Fake</h1> <ul> <li *ngFor="#item of items"> </li> </ul>

有兴趣知道是否有人使用带有角度2.0测试版的templateUrl测试过组件。

谢谢!

1 个答案:

答案 0 :(得分:2)

您应该将ngForCORE_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!!!
})