javascript - Unit testing angular/Ionic project -


I have a very easy controller that looks like this.

  timeInOut.controller ('TimeInOutController', function ($ radius, $ filter, $ ionicScrollDelegate) {...});  

Whenever I try to create a unit test for this ...

  (function () {'use strict'; var Before the scope, the controller first ('TimeInte Controller', function) () (filter) = $ filter; controller = $ (before each (injection (function ($ rootscope, $ controller, $ filter) {scope = $ rootsecope. Controller ('timeInOutController', {$ scope:}}})); Description ('# Date setting', function () {...});}); }) ();  

I get an error:

[$ Injector: unpr] Unknown Provider: $ ionicScrollDelegateProvider & lt; - $ ionicScrollDelegate

Obviously in my example, I'm not trying to inject the $ ionicScrollDelegate in the test, because it's a success Also tried to do the method and failed to include the address failed attempt.

In addition to my karma.conf.js file, I type ionic.bundle.js and angular-mocks.js Libraries / files

I have successfully does not use anything Ionik in which I can test anything, so I know my test framework is set up correctly, the issue of injection If your If you are going to instantiate the controller then you have to pass in all the parameters.

need because I depend on them.

So scoff at my suggestion that represent some of these dependencies and injected them when you are the controller as they do not require the actual services should (not) for your unit tests. Jasmine gives you the ability to create detective objects so that you can inject so that you can verify the behavior of this unit.

  (function () { 'strict use'; var scope, controller, filter, ionicScrollDelegate; description ( 'timeInOutController', function () {beforeEach (Module ( 'common.directives.kmDateToday' )); BeforeEach (inject (function ($ RootScope, $ controller, $ filters) {scope = $ rootScope $ new. (); filter = $ filters; // ionicScrollDelegate that func1 and func2 functions ionicScrollDelegate = jasmine.createSpyObj ( ' ionicScrollDelegate 'will be created as a spy, [' func1 ', the' func2 '] controller = $ controller (' timeInOutController ', ($ scope: the scope, $ filters: filters, $ ionicScrollDelegate: ionicScrollDelegate});}); description ('# Date setting', function () {...}};});}) ();  

You can learn more about Spies through C


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -