【发布时间】:2016-01-12 10:55:53
【问题描述】:
我正在尝试使用 fakeAsync 来测试 Angular 2 组件,但未设置夹具变量。事实上,promise 回调并没有被调用。这是代码:
@Component({
template: '',
directives: [GroupBox, GroupBoxHeader]
})
class TestComponent {
expandedCallback() { this.expandedCalled = true; }
}
it('testing...', inject([TestComponentBuilder], fakeAsync((tcb) => {
var fixture;
tcb.createAsync(TestComponent).then((rootFixture) => {
fixture = rootFixture
});
tick();
fixture.detectChanges();
})));
当我运行这段代码时,我得到:
失败:无法读取未定义的属性“detectChanges” TypeError:无法读取未定义的属性“detectChanges”
我无法弄清楚为什么没有触发回调。在这个存储库中,它工作正常:https://github.com/juliemr/ng2-test-seed/blob/master/src/test/greeting-component_test.ts
有什么线索吗?
注意:我正在使用 ES6、Traceur、Angular 2 beta、Karma 和 Jasmine。
----- 更新 ------
它遵循一个测试失败的存储库:
【问题讨论】:
-
看起来问题出在 TestComponent 上。如果我从组件定义中删除“指令:[GroupBox]”行,则不再发生错误
-
好像是angular 2框架的bug:github.com/angular/angular/issues/5601
-
是的 github.com/juliemr/ng2-test-seed/blob/master/src/test/… 正在工作,因为模板是内联的
标签: unit-testing angular karma-jasmine