0

I have the below AngularJS service class, how can I write Jasmine unit test class for that service?

quoteApp.service('TravelInfoService', function() {
    this.travelAreaTest = function() {
        return 'TESTVAL';
    };
    this.travelAreaDiasbled = function(currentTripType) {
        if (currentTripType.substring(0, 4) == 'SING') {
            return true;
        } else {
            return false;
        }
    };
});

unit test class

describe('sample test', function() {

var travelInfoService = null;

  beforeEach(module('quoteApp'));

  beforeEach(inject(function(TravelInfoService) {
  scope = $rootScope.$new();
  travelInfoService = TravelInfoService;

}));


it('should not be false', function() {
  expect(travelInfoService.travelAreaTest()).toEqual(false);
});

});

This unit-test class is not working so need help to correct it.

  • Please, post what have you tried so far and where have you failed. This service looks pretty basic and there is a lot of information about unit testing angular services in the web. – Michael Radionov May 15 '15 at 09:30
  • I tried to write simple unit test for above service, I have updated my post with unit test class witch i have write, but it is not working. so i wont to know how to write unit test for above anguler Js service – amila basnayake May 15 '15 at 15:46
  • 1
    Why are you expecting `travelAreaTest()` to return `false`? clearly it returns `'TESTVAL'`. – Martin May 15 '15 at 16:08

0 Answers0