Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

NgModelController can't be instantiated by $controller in mock tests #7720

Open
@pocesar

Description

@pocesar

When testing a service, it's impossible right now to instantiate a new ngModelController and create it on the fly, only through $compile and element.controller(), since ngModelController isn't a named controller, but merely a function name inside the angular closure.

the following all fail:

inject(function(NgModelController) { // of course, it isn't a service, there's no provider
});

inject(function($controller, $rootScope) { 
  // it's not a named controller, can't be instantiated, blind shooting with controller names
  // Error: Argument '...' is not a function, got undefined
  $controller('ngModelController', {$scope: $rootScope.$new() }); 
  $controller('NgModelController', {$scope: $rootScope.$new() });
  $controller('NgModel', {$scope: $rootScope.$new() }); 
  $controller('ngModel', {$scope: $rootScope.$new() });
});

Angular does it internal testing relying on the NgModelController function. The only way for it to work is doing

$compile('<input ng-model="dummy">')($rootScope.$new()).controller('ngModel');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions