@@ -6205,154 +6205,113 @@ describe('$compile', function() {
6205
6205
} ) ;
6206
6206
6207
6207
6208
- it ( 'should throw noident when missing controllerAs directive property' , function ( ) {
6209
- module ( function ( $compileProvider ) {
6210
- $compileProvider . directive ( 'noIdent' , valueFn ( {
6211
- templateUrl : 'test.html' ,
6212
- scope : {
6213
- 'data' : '=dirData' ,
6214
- 'oneway' : '<dirData' ,
6215
- 'str' : '@dirStr' ,
6216
- 'fn' : '&dirFn'
6217
- } ,
6218
- controller : function ( ) { } ,
6219
- bindToController : true
6220
- } ) ) ;
6221
- } ) ;
6222
- inject ( function ( $compile , $rootScope ) {
6223
- expect ( function ( ) {
6224
- $compile ( '<div no-ident>' ) ( $rootScope ) ;
6225
- } ) . toThrowMinErr ( '$compile' , 'noident' ,
6226
- 'Cannot bind to controller without identifier for directive \'noIdent\'.' ) ;
6227
- } ) ;
6228
- } ) ;
6229
-
6230
-
6231
- it ( 'should throw noident when missing controller identifier' , function ( ) {
6232
- module ( function ( $compileProvider , $controllerProvider ) {
6233
- $controllerProvider . register ( 'myCtrl' , function ( ) { } ) ;
6234
- $compileProvider . directive ( 'noIdent' , valueFn ( {
6235
- templateUrl : 'test.html' ,
6236
- scope : {
6237
- 'data' : '=dirData' ,
6238
- 'oneway' : '<dirData' ,
6239
- 'str' : '@dirStr' ,
6240
- 'fn' : '&dirFn'
6241
- } ,
6208
+ describe ( 'should bind to controller via object notation' , function ( ) {
6209
+ var controllerOptions = [ {
6210
+ description : 'no controller identifier' ,
6211
+ controller : 'myCtrl'
6212
+ } , {
6213
+ description : '"Ctrl as ident" syntax' ,
6214
+ controller : 'myCtrl as myCtrl'
6215
+ } , {
6216
+ description : 'controllerAs setting' ,
6242
6217
controller : 'myCtrl' ,
6243
- bindToController : true
6244
- } ) ) ;
6245
- } ) ;
6246
- inject ( function ( $compile , $rootScope ) {
6247
- expect ( function ( ) {
6248
- $compile ( '<div no-ident>' ) ( $rootScope ) ;
6249
- } ) . toThrowMinErr ( '$compile' , 'noident' ,
6250
- 'Cannot bind to controller without identifier for directive \'noIdent\'.' ) ;
6251
- } ) ;
6252
- } ) ;
6218
+ controllerAs : 'myCtrl'
6219
+ } ] ,
6253
6220
6221
+ scopeOptions = [ {
6222
+ description : 'isolate scope' ,
6223
+ scope : { }
6224
+ } , {
6225
+ description : 'new scope' ,
6226
+ scope : true
6227
+ } , {
6228
+ description : 'no scope' ,
6229
+ scope : false
6230
+ } ] ,
6254
6231
6255
- it ( 'should bind to controller via object notation (isolate scope)' , function ( ) {
6256
- var controllerCalled = false ;
6257
- module ( function ( $compileProvider , $controllerProvider ) {
6258
- $controllerProvider . register ( 'myCtrl' , function ( ) {
6259
- this . check = function ( ) {
6260
- expect ( this . data ) . toEqualData ( {
6261
- 'foo' : 'bar' ,
6262
- 'baz' : 'biz'
6263
- } ) ;
6264
- expect ( this . oneway ) . toEqualData ( {
6265
- 'foo' : 'bar' ,
6266
- 'baz' : 'biz'
6267
- } ) ;
6268
- expect ( this . str ) . toBe ( 'Hello, world!' ) ;
6269
- expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6270
- } ;
6271
- controllerCalled = true ;
6272
- if ( preAssignBindingsEnabled ) {
6273
- this . check ( ) ;
6274
- } else {
6275
- this . $onInit = this . check ;
6276
- }
6277
- } ) ;
6278
- $compileProvider . directive ( 'fooDir' , valueFn ( {
6279
- templateUrl : 'test.html' ,
6280
- bindToController : {
6281
- 'data' : '=dirData' ,
6282
- 'oneway' : '<dirData' ,
6283
- 'str' : '@dirStr' ,
6284
- 'fn' : '&dirFn'
6285
- } ,
6286
- scope : { } ,
6287
- controller : 'myCtrl as myCtrl'
6288
- } ) ) ;
6289
- } ) ;
6290
- inject ( function ( $compile , $rootScope , $templateCache ) {
6291
- $templateCache . put ( 'test.html' , '<p>isolate</p>' ) ;
6292
- $rootScope . fn = valueFn ( 'called!' ) ;
6293
- $rootScope . whom = 'world' ;
6294
- $rootScope . remoteData = {
6295
- 'foo' : 'bar' ,
6296
- 'baz' : 'biz'
6297
- } ;
6298
- element = $compile ( '<div foo-dir dir-data="remoteData" ' +
6299
- 'dir-str="Hello, {{whom}}!" ' +
6300
- 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
6301
- $rootScope . $digest ( ) ;
6302
- expect ( controllerCalled ) . toBe ( true ) ;
6303
- } ) ;
6304
- } ) ;
6232
+ templateOptions = [ {
6233
+ description : 'inline template' ,
6234
+ template : '<p>template</p>'
6235
+ } , {
6236
+ description : 'templateUrl setting' ,
6237
+ templateUrl : 'test.html'
6238
+ } , {
6239
+ description : 'no template'
6240
+ } ] ;
6305
6241
6242
+ forEach ( controllerOptions , function ( controllerOption ) {
6243
+ forEach ( scopeOptions , function ( scopeOption ) {
6244
+ forEach ( templateOptions , function ( templateOption ) {
6245
+
6246
+ var description = [ ] ,
6247
+ ddo = {
6248
+ bindToController : {
6249
+ 'data' : '=dirData' ,
6250
+ 'oneway' : '<dirData' ,
6251
+ 'str' : '@dirStr' ,
6252
+ 'fn' : '&dirFn'
6253
+ }
6254
+ } ;
6306
6255
6307
- it ( 'should bind to controller via object notation (new scope)' , function ( ) {
6308
- var controllerCalled = false ;
6309
- module ( function ( $compileProvider , $controllerProvider ) {
6310
- $controllerProvider . register ( 'myCtrl' , function ( ) {
6311
- this . check = function ( ) {
6312
- expect ( this . data ) . toEqualData ( {
6313
- 'foo' : 'bar' ,
6314
- 'baz' : 'biz'
6256
+ forEach ( [ controllerOption , scopeOption , templateOption ] , function ( option ) {
6257
+ description . push ( option . description ) ;
6258
+ delete option . description ;
6259
+ extend ( ddo , option ) ;
6315
6260
} ) ;
6316
- expect ( this . data ) . toEqualData ( {
6317
- 'foo' : 'bar' ,
6318
- 'baz' : 'biz'
6261
+
6262
+ it ( '(' + description . join ( ', ' ) + ')' , function ( ) {
6263
+ var controllerCalled = false ;
6264
+ module ( function ( $compileProvider , $controllerProvider ) {
6265
+ $controllerProvider . register ( 'myCtrl' , function ( ) {
6266
+ this . check = function ( ) {
6267
+ expect ( this . data ) . toEqualData ( {
6268
+ 'foo' : 'bar' ,
6269
+ 'baz' : 'biz'
6270
+ } ) ;
6271
+ expect ( this . oneway ) . toEqualData ( {
6272
+ 'foo' : 'bar' ,
6273
+ 'baz' : 'biz'
6274
+ } ) ;
6275
+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
6276
+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6277
+ } ;
6278
+ controllerCalled = true ;
6279
+ if ( preAssignBindingsEnabled ) {
6280
+ this . check ( ) ;
6281
+ } else {
6282
+ this . $onInit = this . check ;
6283
+ }
6284
+ } ) ;
6285
+ $compileProvider . directive ( 'fooDir' , valueFn ( ddo ) ) ;
6286
+ } ) ;
6287
+ inject ( function ( $compile , $rootScope , $templateCache ) {
6288
+ $templateCache . put ( 'test.html' , '<p>template</p>' ) ;
6289
+ $rootScope . fn = valueFn ( 'called!' ) ;
6290
+ $rootScope . whom = 'world' ;
6291
+ $rootScope . remoteData = {
6292
+ 'foo' : 'bar' ,
6293
+ 'baz' : 'biz'
6294
+ } ;
6295
+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
6296
+ 'dir-str="Hello, {{whom}}!" ' +
6297
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
6298
+ $rootScope . $digest ( ) ;
6299
+ expect ( controllerCalled ) . toBe ( true ) ;
6300
+ if ( ddo . controllerAs || ddo . controller . indexOf ( ' as ' ) !== - 1 ) {
6301
+ if ( ddo . scope ) {
6302
+ expect ( $rootScope . myCtrl ) . toBeUndefined ( ) ;
6303
+ } else {
6304
+ // The controller identifier was added to the containing scope.
6305
+ expect ( $rootScope . myCtrl ) . toBeDefined ( ) ;
6306
+ }
6307
+ }
6308
+ } ) ;
6319
6309
} ) ;
6320
- expect ( this . str ) . toBe ( 'Hello, world!' ) ;
6321
- expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6322
- } ;
6323
- controllerCalled = true ;
6324
- if ( preAssignBindingsEnabled ) {
6325
- this . check ( ) ;
6326
- } else {
6327
- this . $onInit = this . check ;
6328
- }
6310
+
6311
+ } ) ;
6329
6312
} ) ;
6330
- $compileProvider . directive ( 'fooDir' , valueFn ( {
6331
- templateUrl : 'test.html' ,
6332
- bindToController : {
6333
- 'data' : '=dirData' ,
6334
- 'oneway' : '<dirData' ,
6335
- 'str' : '@dirStr' ,
6336
- 'fn' : '&dirFn'
6337
- } ,
6338
- scope : true ,
6339
- controller : 'myCtrl as myCtrl'
6340
- } ) ) ;
6341
- } ) ;
6342
- inject ( function ( $compile , $rootScope , $templateCache ) {
6343
- $templateCache . put ( 'test.html' , '<p>isolate</p>' ) ;
6344
- $rootScope . fn = valueFn ( 'called!' ) ;
6345
- $rootScope . whom = 'world' ;
6346
- $rootScope . remoteData = {
6347
- 'foo' : 'bar' ,
6348
- 'baz' : 'biz'
6349
- } ;
6350
- element = $compile ( '<div foo-dir dir-data="remoteData" ' +
6351
- 'dir-str="Hello, {{whom}}!" ' +
6352
- 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
6353
- $rootScope . $digest ( ) ;
6354
- expect ( controllerCalled ) . toBe ( true ) ;
6355
6313
} ) ;
6314
+
6356
6315
} ) ;
6357
6316
6358
6317
0 commit comments