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