Javascript 如何测试名为';sample.Svc';在我的模块中使用摩卡&x2B;柴
我的服务文件service.jsJavascript 如何测试名为';sample.Svc';在我的模块中使用摩卡&x2B;柴,javascript,angularjs,mocha.js,naming,karma-mocha,Javascript,Angularjs,Mocha.js,Naming,Karma Mocha,我的服务文件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.showModalDi
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);
}
};
}]);
我的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;
});
});
运行我的serviceSpec.js
(使用Karma)我犯了这样的错误 “SyntaxError:分析错误” 我知道这个错误是由参数名(sample.Svc)和“
”引起的。但是我不知道在我的测试用例中使用我的服务“sample.Svc
”的其他方法。有人帮助我以任何其他方式注入我的服务
其他人使用点命名服务,我有权更改它们。所以我需要一些具有相同命名结构的解决方案。提前感谢。尝试使用命名约定的最佳实践。你将节省大量的时间和头痛
编辑:若要详细说明,请将您的服务称为“示例”或类似的名称。谢谢您的建议,但我必须遵循与前面所述相同的命名约定。