angularjs - Angular/Jasmine: is failing using classes for factory and services -


finally, got run test jasmine , succesfully of test standard mode.

i tried change way declare factory , service class constructor each class , necessary parameters. failing test now.

what don't understand opened in browser test , chrome set breakpoints. in factory call, in service call. in test set breakpoints after beforeeach , inside inject. set breakpòints inside factory class , chrom,e doesn't stop there.

when execute test location handler returning undefined in lh variable, obiously, 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 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 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]); 

i think problem you're trying register "service" controller @ bottom of localizationservice.

try , use

app.service("localizationservice", [localizationservice]); 

instead of

app.controller("localizationservice", [localizationservice]); 

but in end in don't understand why want use service and factory in example. maybe check out:

confused service vs factory


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -