javascript - angularjs injector with location service -


I have some angular with Jasmine To do this, I need an angular injector:

  var Injector = angular index (['ng', 'ngrut', 'main module']);  

This works fine, but when I test a controller that uses $ space, I have to add that injector:

  var Injector = angular indicator (['ng', 'ngrut', 'position', 'main module']);  

Now it throws an error:

  Error: Error: Failed to instantiate module space due to [$ Injector: Modular]: Error: [$ Injector: Named] module 'Location' is not available! You either misspelled the name of the module or forgot to load it. If a module is registering, make sure you specify the dependency in the form of the second argument.  

How can I include the $ location service there? Thank you.

-------------- Edit -----------------

Many people No Answer I thought I would add some details.

Here's the controller I'm trying to test (or its definition, I will not paste all the code):

  var app = angular.module 'MainModule'); App.controller ('appController', ['$ window', '$ scope', '$ location', '$ wsService', '$ userService', '$ labelService', function ($ window, $ scope, $ location, $ WsService, $ userService, $ label service) {controller's // unit}]);  

You have already seen how I make injector in my unit test in the original post, here's how I use the injector to make the controller:

  Miscellaneous scope; Var Controller; Var getController = function () [injector.invoke (['$ rootScope', '$ controller', function ($ rootsecope, $ controller) {scope = $ rootScope. $ New (); Controller = $ controller ('appController' {$ Area: area});}]); };  

Hope this will help in generating some possible answers. Thanks

How to test the following controller to answer my own question:

  var app = angular Module ('main module'); App.controller ('body', 'appController', ['$ window', '$ scope', '$ location', '$ userService', function ($ window, $ radius, $ position, $ userService)) ]); To create an injector in the unit test:  
  var Injector = angular index (['ng', 'ngrur']  

1 , 'main module']);

}];

3 Fake location service:

  var mockLocation = {path: ""}};  

For the controller I just need the path , so I did not make fun of anything else, but duplicate whatever you need.

4 Call the administrator:

  var scope; Var Controller; Var getController = function () {injector.invoke (['$ rootScope', '$ controller', function ($ rootScope, $ controller) {scope = $ rootScope. $ New (); Controller = $ controller ('appController' {$ Area: area, $ location: mock location});}]); };  

Now the controller can be used in unit tests.
It can get rid of 'Unknown Provider' and other service related errors.
The blog post gave me an answer, thanks to the author.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -