Finally, I got to run test with jasmine and was succesfully all of my test with the standard mode.
I tried to change the way to declare my factory and service like a class with the constructor for each class and the necessary parameters. It is failing the test now.
What I don't understand I opened in browser my test and with Chrome I set my breakpoints. in the factory call, in service call. Finally in test I set breakpoints after the beforeEach and inside the inject. I set some breakpòints inside factory class and Chrom,e doesn't stop there.
When I execute the test the Location handler is returning undefined in lh variable, obiously, the call of functions inside factory fails.
My test is:
/// <reference path="../../../_references.js" />
describe("Factory - LocalizationHandler", function () {
var lh;
beforeEach(module('appCookIn.Factory'));
beforeEach(function () {
inject(function (LocalizationHandler, LocalizationService, $http, $q) {
lh = LocalizationHandler;
});
});
///
/// Testea que la funcion de GetConcept la devuelva coorectamente
///
it("LocalizationHandler - GetConcept", function () {
// Arrange
var Expected = 'Nombre';
var json = lh.SetNewCulture("es-ES");
// Act
var Result = lh.GetConcept(1);
// Assert
expect(Result).toBe(Expected);
});
///
/// Cambia la localización actual a otra.
///
it("LocalizationHandler - SetNewCulture", function () {
// Arrange
var ExpectedCulture = "es-ES";
var ExpectedResult = true;
// Act
var Result = lh.SetNewCulture("es-ES");
var ResultCulture = lh.GetCurrentCulture();
// Assert
expect(ResultCulture).toBe(ExpectedCulture);
expect(Result).toBe(ExpectedResult);
});
it("LocalizationHandler - GetCurrentCulture", function () {
// Arrange
var Expected = "es-ES";
lh.SetNewCulture(Expected);
// Act
var Result = lh.GetCurrentCulture();
// Assert
expect(Result).toBe(Expected);
});
});
My factory is:
LocalizationHandler = function (LocalizationService, $http, $q) {
var self = this;
self.LocalizationItems = null;
self.culture = "es-ES";
var res = {
GetCurrentCulture: function ()
{
return self.culture;
},
SetNewCulture: function (culture)
{
var data = JSON.parse(LocalizationService.SetNewCulture());
self.LocalizationItems = data[culture];
self.culture = culture;
return self.LocalizationItems != null;
},
GetConcept: function (enumerable)
{
if (self.LocalizationItems == null) return;
return self.LocalizationItems[enumerable];
}
}
self.LocalizationConstructor = function (res) {
res.SetNewCulture(res.GetCurrentCulture());
};
self.LocalizationConstructor(res);
return res;
};
app.factory("LocalizationHandler", ["LocalizationService", "$http", "$q", LocalizationHandler]);
And my service is:
///
/// El servicio de localización trata el tema de la cultura para visualización de variables.
///
LocalizationService = function () {
var self = this;
self.LocalizationItems = null;
self.culture = "es-ES";
self.SetNewCulture = function () {
var res = "";
res += '{';
res += '"es-ES": {';
res += '"1": "Nombre",';
res += '"2": "Llave de entrada"';
res += '},';
res += '"ca-ES": {';
res += '"1": "Nom",';
res += '"2": "Clau d`entrada"';
res += '}';
res += '}';
return res;
};
self.LocalizationServiceCtor = function () {
}
self.LocalizationServiceCtor();
}
app.controller("LocalizationService", [LocalizationService]);