茉莉花中发生了一些奇怪的事情。我的代码在Angular中工作,但是当我在jasmin中执行$ http.get时,它无效。
我的工厂
app.factory('LocalizationHandler', ['$http', '$q', function ($http, $q) {
var self = this;
var res = {
SetNewCulture: function (culture)
{
console.log("Inside SetNewCulture");
self.culture = culture;
var res = "";
var defer = $q.defer();
$http.get("Scripts/Lib/Factories/Localization/CookinConcepts.json").success(function (response)
{
console.log("estoy dentro");
defer.resolve(response);
return defer.promise;
}).
error(function (e) {
console.log("ERROR");
}).
then(function (response)
{
console.log("OKEY");
self.LocalizationItems = response.data[self.culture];
});
return defer.promise;
}
}
self.LocalizationConstructor = function () {
res.SetNewCulture(res.GetCurrentCulture());
self.LocalizationItems = null;
self.culture = "ca-ES";
};
self.LocalizationConstructor();
return res;
}]);
我的测试是:
/// <reference path="../../../_references.js" />
describe("Factory - LocalizationHandler", function () {
var lh;
beforeEach(module('appCookIn'));
beforeEach(function () {
inject(function (LocalizationHandler) {
lh = LocalizationHandler;
});
});
it("LocalizationHandler - SetNewCulture", function () {
// Arrange
var expected = "es-ES";
// Act
var result = lh.SetNewCulture("es-ES");
// Assert
expect(result).not.toBe(expected);
});
});
console.log
我只看到OutPut窗口中的下一个文字:Inside SetNewCulture
。
在测试项目或主项目中应该记录JSON文件吗?
为什么在测试函数$ http不起作用?应该geta json归档我的文化吗?