我有一個基於折扣,數量等來計算產品價格的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