My service file service.js
angular.module('services', [])
.service('sample.Svc', ['$window', 'modalSvc', function($window, modalSvc){
this.showDialog = function(message, title){
console.log(" in here");
if(title){
modalSvc.showModalDialog({
title: title,
message: message
});
} else {
$window.alert(message);
}
};
}]);
My serviceSpec.js
describe('service tests', function(){
var mockWindow, mockModalSvc, sampleSvcObj;
beforeEach(function(){
module(function($provide){
$provide.service('$window', function(){
this.alert = sinon.spy();
});
$provide.service('modalSvc', function(){
this.showModalDialog = sinon.spy();
});
});
module('services');
});
beforeEach(inject(function($window, modalSvc, sample.Svc){
mockWindow=$window;
mockModalSvc=modalSvc;
sampleSvcObj=sampleSvc;
}));
it('Need to pass', function() {
expect(false).to.be.false;
});
});
While running my serviceSpec.js
(using Karma)
I am getting error like
"SyntaxError: Parse error".
I know this error caused due to the argument name(sample.Svc) with '.
'. But I dont know other ways to use my service "sample.Svc
" in my testcases. Some body help me to inject my service in any other way.
Services are named by using dot by others, I have permission to change them. So I need some solution with same naming structure.
Thanks in advance.
Try using best practices for naming conventions. You will save a lot of time and headaches
https://github.com/mgechev/angularjs-style-guide#services
Edit: to elaborate, call your service "Sample" or something like that.