【发布时间】:2016-02-15 09:51:30
【问题描述】:
我的服务文件 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);
}
};
}]);
我的 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)
我收到类似的错误
“语法错误:解析错误”。
我知道这个错误是由带有“.”的参数名称(sample.Svc)引起的。但我不知道在我的测试用例中使用我的服务“sample.Svc”的其他方法。一些机构帮助我以任何其他方式注入我的服务。
服务是别人用点命名的,我有权更改。所以我需要一些具有相同命名结构的解决方案。
提前致谢。
【问题讨论】:
标签: javascript angularjs mocha.js naming karma-mocha