TypeError:无法获取属性' setPromocodeDetails'未定义或空引用

时间:2015-12-02 12:21:42

标签: angularjs unit-testing jasmine

我已将我的服务定义为

angular.module('myservice', []).service('dataService', function() {
  var promocodeDetails = {
    "havePromocode": false,
    "promocode": "",
    "OfferHeading": "",
    "OfferDescription": "",
    "OfferDisclaimer": ""
  };
  return {
    setPromocodeDetails: function(promocode) {
      promocodeDetails = promocode;
    },
    getPromocodeDetails: function() {
      return promocodeDetails;
    }
  };
});

我为它编写了茉莉花测试

describe('Testing dataservice - a service', function() {
  beforeEach(function() {
    module('myservice');
  });
  var dataService;
  beforeEach(inject(function(_dataService_) {
    dataService = _dataService_;
  }));
  it('should set the promocodedetail', function() {
    var promocode = {
      'promocode':'12345'
    }
    dataService.setPromocodeDetails(promocode);
    expect(dataService.getPromocodeDetails().promocode).toEqual('12345');
  });
});

当我尝试运行此测试时,出现以下错误

TypeError: Unable to get property 'setPromocodeDetails' of undefined or null reference

请建议我坚持这个简单的测试...

0 个答案:

没有答案