我正在尝试使用 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();
})));
当我运行此代码时,我得到:
Failed: Cannot read property 'detectChanges' of undefined TypeError: Cannot read property 'detectChanges' of undefined
我不明白为什么回调没有被触发。在此存储库中,它工作正常:https://github.com/juliemr/ng2-test-seed/blob/master/src/test/greeting-component_test.ts
有什么线索吗?
注意:我使用的是 ES6、Traceur、Angular 2 beta、Karma 和 Jasmine。
------更新------
它遵循测试失败的存储库:
最佳答案
TestComonentBuilder
不适用于 templateUrl
https://github.com/angular/angular/issues/5662
关于unit-testing - 使用 fakeAsync 进行 Angular2 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34741775/