我有一个与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([]); }
}
};