title: SpyOn calling actual implementation of method
body: <p>I am trying to write unit-test test cases for an angular application and I am using <code>SpyOn()</code> method to spy on a service method.  </p>
  
  <p>I am testing a service that has a method called <code>getCurrentBoardTimeIdByCurrentTime()</code> which internally calls another service method called<br>
  <code>utilService.getHour()</code> and <code>utilService.getWeekday()</code></p>
  
  <p>I have used spies on these 2 methods and returned number <code>2</code> and <code>5</code> respectively after which the <code>getCurrentBoardTimeIdByCurrentTime()</code> must return <code>7</code>.</p>
  
  <p>Now when I call the service method <code>getCurrentBoardTimeIdByCurrentTime()</code> the return value from spy is not used, instead the actual function itself is being called causing test to fail.</p>
  
  <p>BoardSharedService.spec.ts</p>
  
  <pre><code>describe('BoardSharedService', () =&gt; {
    let service: BoardSharedService;
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        providers: [
          BoardSharedService,
          UtilService
        ]
      });
    });
  
    it('should fetch data', () =&gt; {
      service = TestBed.get(BoardSharedService);
      const getHourSpy = jasmine.createSpyObj('UtilService', ['getHour']);
      const getWeekDaySpy = jasmine.createSpyObj('UtilService', ['getWeekDay']);
  
      getHourSpy.getHour.and.returnValue(2);
      getWeekDaySpy.getWeekDay.and.returnValue(5);
  
      expect(service.getCurrentBoardTimeIdByCurrentTime()).toBe(7);
      expect(service.getCurrentBoardTimeIdByCurrentTime).toHaveBeenCalled();
    });
  
  });
  </code></pre>
  
  <p>and boardSharedService.ts</p>
  
  <pre><code>@Injectable()
  export class BoardSharedService {
  
    constructor(private utilService: UtilService) { }
  
    getCurrentBoardTimeIdByCurrentTime() {
      const currentHour = this.utilService.getHour();
      const currentDay = this.utilService.getWeekDay();
      if (currentHour &lt; 6 || currentHour &gt; 17) {
        // PM
        if (currentDay === Day.Friday) {
          return 7; // Friday PM
        } 
      }
    }
  }
  </code></pre>
  
  <p>and I get the following error</p>
  
  <pre><code>BoardSharedService should fetch data
  Expected 1 to be 7.
  Error: Expected 1 to be 7.
  </code></pre>
  
  <p>Need help.!</p>
  
  <p>Thank you</p>