benjamincharity
11/9/2017 - 3:08 PM

Create helper method to spy on service method.

export MyServiceMock {
  spies: { [id: string]: jasmine.Spy }

  _spies(method: string): jasmine.Spy {
    if ( !this.spies[method] ) {
      this.spies[method] =  jasmine.createSpy(method);
    }

    return this[method] = this.spies[method];
  }

}

// Usage:
myServiceMock._spy('getLoggedInUserId').and.callFake(() => {})