如何对依赖ActivatedRoute取消订阅的组件进行单元测试?

时间:2017-02-02 17:52:37

标签: unit-testing angular components observable unsubscribe

我有一个与How to unit test a component that depends on parameters from ActivatedRoute?

类似的问题

基本上我是单元测试具有ActivatedRoute依赖性的组件。我的组件中也有unsubscribe方法:

ngOnDestroy() {
this.subscription.unsubscribe();

}

我收到以下错误:

TypeError: Cannot read property 'unsubscribe' of undefined

我尝试过如下模拟ActiveRoot,但订阅是void所以我不确定如何测试它!

let mockActivatedRoute = {
data: {
  subscribe: (fn: (value: Data) => void) => fn({
    yourData: 'yolo'
  })
},
params: {
  next: Observable.of([0]),
  subscribe: () => { Observable.of([]); }
}

};

0 个答案:

没有答案