vendredi 24 mars 2017

How to mock nested service functions in Jasmine

I am trying to mock a function thats is been called by another function inside the service 'billsService' but it does not work, it gives the error:

✗ test FUNC isExpireDateToday
Expected false to be truthy. at Object. (www/app/contas/billsService.spec.js:102:45)

 function isExpireDateToday (dataContaSemHoras) {
  return isHoliday(dataContaSemHoras)
}

describe('Bills Service', function () {
   var service
   beforeEach(angular.mock.module('app'))
   beforeEach(inject(function (billsService) {
     service = billsService
   }))

  it('test FUNC isExpireDateToday', function () {
    var date = new Date()
    date.setHours(0, 0, 0, 0)
    spyOn(service, 'isExpireDateToday').and.callThrough()
    spyOn(service, 'isHoliday').and.returnValue(true)

    expect(service).toBeDefined()
    expect(service.isExpireDateToday(date)).toBeTruthy() // line 102
  })
})

Aucun commentaire:

Enregistrer un commentaire