@@ -2196,8 +2196,8 @@ angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
2196
2196
* A service that can be used to create instances of component controllers.
2197
2197
* <div class="alert alert-info">
2198
2198
* Be aware that the controller will be instantiated and attached to the scope as specified in
2199
- * the component definition object. That means that you must always provide a `$scope` object
2200
- * in the `locals` param .
2199
+ * the component definition object. If you do not provide a `$scope` object in the `locals` param
2200
+ * then the helper will create a new isolated scope as a child of `$rootScope` .
2201
2201
* </div>
2202
2202
* @param {string } componentName the name of the component whose controller we want to instantiate
2203
2203
* @param {Object } locals Injection locals for Controller.
@@ -2207,7 +2207,7 @@ angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
2207
2207
* @return {Object } Instance of requested controller.
2208
2208
*/
2209
2209
angular . mock . $ComponentControllerProvider = [ '$compileProvider' , function ( $compileProvider ) {
2210
- this . $get = [ '$controller' , '$injector' , function ( $controller , $injector ) {
2210
+ this . $get = [ '$controller' , '$injector' , '$rootScope' , function ( $controller , $injector , $rootScope ) {
2211
2211
return function $componentController ( componentName , locals , bindings , ident ) {
2212
2212
// get all directives associated to the component name
2213
2213
var directives = $injector . get ( componentName + 'Directive' ) ;
@@ -2225,6 +2225,9 @@ angular.mock.$ComponentControllerProvider = ['$compileProvider', function($compi
2225
2225
}
2226
2226
// get the info of the component
2227
2227
var directiveInfo = candidateDirectives [ 0 ] ;
2228
+ // create a scope if needed
2229
+ locals = locals || { } ;
2230
+ locals . $scope = locals . $scope || $rootScope . $new ( true ) ;
2228
2231
return $controller ( directiveInfo . controller , locals , bindings , ident || directiveInfo . controllerAs ) ;
2229
2232
} ;
2230
2233
} ] ;
0 commit comments