Jasmine: how to mock a class and expect on the instance method

Viewed 25

I want to test the standard SubSink strategy. So there is the SubSink class

...
export class SubSink {
  protected subs = new Subscription();
...
  unsubscribe() {
    this.subs.unsubscribe();
  }
}

and in my component

...
private sub: SubSink = new SubSink();
...
ngOnDestroy(): void {
  console.log('called');
  this.sub.unsubscribe();
}

in my test I'd like to test that this.sub.unsubscribe has been called. I've tried something like this:

    mockSubSinkClass = jasmine.createSpyObj('SubSink', ['unsubscribe']);
....
    { provide: SubSink, useValue: mockSubSinkClass }

but can't really figure it out what to do with it in the expectation. "called" gets logged, but any tried expectation fails.

0 Answers
Related