Menu

#7 Unit testing

closed
nobody
None
2016-11-28
2014-09-10
Anonymous
No

Originally created by: jlambert121

Thank you for this great addition to angular, I love the flexibility and ease of use.

I am trying to write unit tests for a controller I'm using in a modal and cannot figure out how to inject the close provider into my tests since it looks like there's some angular magic going on. Any tips to help?

it('should implement close()', function () {
      inject(function ($controller, $rootScope) {
        var scope;

        scope = $rootScope.$new();
        $controller('TemplateController', { $scope: scope } );

        expect(angular.isFunction(scope.close)).toBeTruthy();
      });
    }); // should implement close()

The controller is as simple as:

TimelineControllers.controller('TemplateController', ['$scope', 'close', function($scope, close) {
    $scope.close = function () {
      close('i was closed');
    };
  }]);

Related

Tickets: #40

Discussion

  • Anonymous

    Anonymous - 2014-10-14

    Originally posted by: dwmkerr

    Hi @jlambert121 sorry for the late reply, let me raise an issue to document unit testing with Angular Modal Service, hopefully this should be useful!\

     
  • 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.