Menu

#40 Howto test the ModalController ?

open
nobody
None
2016-11-28
2015-02-25
Anonymous
No

Originally created by: campa

Hi can you help me writing unit test for modal controllers ?

I tried but I'm not able to solve these errors:

  • Error: [$injector:unpr] Unknown provider: $elementProvider <- $element <- PartsEditmenudialogctrlCtrl
    Or
  • Error: [$injector:unpr] Unknown provider: closeProvider <- close <- PartsEditmenudialogctrlCtrl

PLease, can you add a controller test to your complexcontroller example ?

My interesting part of the test code is:

beforeEach(inject(function ($controller, $rootScope) {    
    scope = $rootScope.$new();
    PartsEditmenudialogctrlCtrl = $controller('PartsEditmenudialogctrlCtrl', {
      $scope: scope
    });

and for the controller

.controller('PartsEditmenudialogctrlCtrl', [ '$route', '$scope' , '$log', 'growl', 'MainMenuService', '$element', 'close', 'currMainMenuEditData', 
                                               function ($route, $scope, $log, growl, MainMenuService, $element, close, currMainMenuEditData) {

Thanks in advance
Stefano

Discussion

  • Anonymous

    Anonymous - 2015-02-27

    Originally posted by: dwmkerr

    I'll write up a quite tutorial ASAP @campa and then update this article, (@dwmkerr see also [#7])

     

    Related

    Tickets: #7

  • Anonymous

    Anonymous - 2016-01-17

    Originally posted by: sajadghobadi

    first define below line

      var element = angular.element('<div></div>');
    
     hadithListCtrl = $controller('hadithListCtrl', { $element:element });
    

    after write mentioned lines in before function you donot see this error

     
  • Anonymous

    Anonymous - 2016-11-28

    Originally posted by: PratibhaP

    I also have the same issue, the only difference is that using custom modal, so, I don't need a $element.

    Error: [$injector:unpr] Unknown provider: closeProvider <- close <- changePasswordController

    while running unit testing. Can you help please me.

    Thank you in advance.

     

Log in to post a comment.