我有一个基于折扣,数量等来计算产品价格的angularjs服务。我试图编写一个茉莉花测试来调用此服务,并传入测试数据。我收到一个错误,表示应用程序缺少依赖关系。我不想加载Ui路由器,不应该嘲笑这件事吗?设置Jasmine AngularJS服务测试时未知的提供商
Error: [$injector:nomod] Module 'ui.router' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
这是我的Jasmine SpecRunner.html。我正在测试的Web项目与我的Jasmine测试项目不同。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jasmine Spec Runner v2.0.0</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>
<script src="http://localhost:54411/Scripts/vendor/angular.js"></script>
<script src="http://localhost:54411/Scripts/vendor/angular-mocks.js"></script>
<script src="http://localhost:54411/Scripts/app.js"></script>
<!-- include source files here... -->
<script src="http://localhost:54411/Scripts/services/productPriceCalculatorSvc.js"></script>
<!-- include spec files here... -->
<script src="spec/ProductPriceCalculatorSpec.js"></script>
</head>
<body>
</body>
</html>
该规范文件:
describe("Product Price Calculator service test", function() {
describe("when I call product price calculator.calculateCustomerDiscPrice", function() {
var sut;
beforeEach(function() {
module('quoteMasterApp');
inject(function(productPriceCalculatorSvc) {
sut = productPriceCalculatorSvc;
});
});
it('can calculate customer discount price', function() {
productPriceCalculatorSvc.calculateCustomerDiscPrice(null, null);
});
});
});
这里是我的服务宣言。
myApp.service("productPriceCalculatorSvc", [
function() {
return {
calculateCustomerDiscPrice: function(product, conversionRate) {
// calculations occur here
});
}
}
}
])
什么是您正在引用的productPriceCalculatorSvcFactory?我的应用程序不使用工厂的服务。 –
这应该很容易。没有依赖关系的单一服务。在4小时内都没有取得进展:(我还以为angularjs被假设是可测试 –
有没有遇到什么成功 – shortfinals