【发布时间】:2020-08-15 16:57:26
【问题描述】:
我在 Angular 7 中第一次尝试 Jasmine 测试用例。我有一个 observable,它使用服务文件中的 next() 发出数据。组件订阅 observable 并使用数据。这是ngOnInit中的代码
ngOnInit() {
this.loading = true;
this.subscribe(this.advDirectService.directive$, data => {
this.directives = data;
this.loading = false;
});
this.advDirectService.loadDirective(); }
我可以预期会调用 loadDirective。但是当我试图期待 this.directives 它总是说 NULL。我的组件扩展了 BaseComponent。请帮助我学习如何为订阅块内的代码编写测试。
【问题讨论】: