I have a method like this in my service
angular.module('App')
.factory("AppService", [function() {
var _admin;
return {
get admin() {
return _admin;
},
};
}]);
In my controller
i am using it like this:
$scope.show = function(){
return AppService.admin === 0 || (AppService.admin !== 0 && AppService.admin === true);
};
When i am trying to test the function
, i am getting an error like below:
it('calls the showAutoPay method', function () {
$scope.show();
expect($scope.show).to
.have.been.calledOnce;
expect(service.admin).to.not.equal(null);
assert.equal(service.admin, '0');
});
I am also not sure how to mock the AppService
which has the get
and set
methods.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…