1

I have a similar question as How to unit test a component that depends on parameters from ActivatedRoute?

Basically I'm unit testing a component which has ActivatedRoute dependency. I also have unsubscribe method in my component:

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

}

I'm getting the following error:

TypeError: Cannot read property 'unsubscribe' of undefined

I have tried mocking ActiveRoot as below, but subscription is void so I'm not sure how to test this!

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

};

Community
  • 1
  • 1
shiva
  • 714
  • 10
  • 25

0 Answers0