@@ -11151,32 +11151,39 @@ describe('$compile', function() {
11151
11151
}
11152
11152
11153
11153
describe ( 'ngAttr* attribute binding' , function ( ) {
11154
-
11155
- it ( 'should bind after digest but not before' , inject ( function ( $compile , $rootScope ) {
11154
+ it ( 'should bind after digest but not before' , inject ( function ( ) {
11156
11155
$rootScope . name = 'Misko' ;
11157
11156
element = $compile ( '<span ng-attr-test="{{name}}"></span>' ) ( $rootScope ) ;
11158
11157
expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
11159
11158
$rootScope . $digest ( ) ;
11160
11159
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
11161
11160
} ) ) ;
11162
11161
11163
- it ( 'should bind after digest but not before when after overridden attribute' , inject ( function ( $compile , $rootScope ) {
11162
+ it ( 'should bind after digest but not before when after overridden attribute' , inject ( function ( ) {
11164
11163
$rootScope . name = 'Misko' ;
11165
11164
element = $compile ( '<span test="123" ng-attr-test="{{name}}"></span>' ) ( $rootScope ) ;
11166
11165
expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11167
11166
$rootScope . $digest ( ) ;
11168
11167
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
11169
11168
} ) ) ;
11170
11169
11171
- it ( 'should bind after digest but not before when before overridden attribute' , inject ( function ( $compile , $rootScope ) {
11170
+ it ( 'should bind after digest but not before when before overridden attribute' , inject ( function ( ) {
11172
11171
$rootScope . name = 'Misko' ;
11173
11172
element = $compile ( '<span ng-attr-test="{{name}}" test="123"></span>' ) ( $rootScope ) ;
11174
11173
expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11175
11174
$rootScope . $digest ( ) ;
11176
11175
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
11177
11176
} ) ) ;
11178
11177
11179
- it ( 'should remove attribute if any bindings are undefined' , inject ( function ( $compile , $rootScope ) {
11178
+ it ( 'should set the attribute (after digest) even if there is no interpolation' , inject ( function ( ) {
11179
+ element = $compile ( '<span ng-attr-test="foo"></span>' ) ( $rootScope ) ;
11180
+ expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
11181
+
11182
+ $rootScope . $digest ( ) ;
11183
+ expect ( element . attr ( 'test' ) ) . toBe ( 'foo' ) ;
11184
+ } ) ) ;
11185
+
11186
+ it ( 'should remove attribute if any bindings are undefined' , inject ( function ( ) {
11180
11187
element = $compile ( '<span ng-attr-test="{{name}}{{emphasis}}"></span>' ) ( $rootScope ) ;
11181
11188
$rootScope . $digest ( ) ;
11182
11189
expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
@@ -11189,6 +11196,8 @@ describe('$compile', function() {
11189
11196
} ) ) ;
11190
11197
11191
11198
describe ( 'in directive' , function ( ) {
11199
+ var log ;
11200
+
11192
11201
beforeEach ( module ( function ( ) {
11193
11202
directive ( 'syncTest' , function ( log ) {
11194
11203
return {
@@ -11209,47 +11218,52 @@ describe('$compile', function() {
11209
11218
} ) ;
11210
11219
} ) ) ;
11211
11220
11212
- beforeEach ( inject ( function ( $templateCache ) {
11221
+ beforeEach ( inject ( function ( $templateCache , _log_ ) {
11222
+ log = _log_ ;
11213
11223
$templateCache . put ( 'async.html' , '<h1>Test</h1>' ) ;
11214
11224
} ) ) ;
11215
11225
11216
11226
it ( 'should provide post-digest value in synchronous directive link functions when after overridden attribute' ,
11217
- inject ( function ( log , $rootScope , $compile ) {
11218
- $rootScope . test = 'TEST' ;
11219
- element = $compile ( '<div sync-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
11220
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11221
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11222
- } ) ) ;
11227
+ function ( ) {
11228
+ $rootScope . test = 'TEST' ;
11229
+ element = $compile ( '<div sync-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
11230
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11231
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11232
+ }
11233
+ ) ;
11223
11234
11224
11235
it ( 'should provide post-digest value in synchronous directive link functions when before overridden attribute' ,
11225
- inject ( function ( log , $rootScope , $compile ) {
11226
- $rootScope . test = 'TEST' ;
11227
- element = $compile ( '<div sync-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
11228
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11229
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11230
- } ) ) ;
11236
+ function ( ) {
11237
+ $rootScope . test = 'TEST' ;
11238
+ element = $compile ( '<div sync-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
11239
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11240
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11241
+ }
11242
+ ) ;
11231
11243
11232
11244
11233
11245
it ( 'should provide post-digest value in asynchronous directive link functions when after overridden attribute' ,
11234
- inject ( function ( log , $rootScope , $compile ) {
11235
- $rootScope . test = 'TEST' ;
11236
- element = $compile ( '<div async-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
11237
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11238
- $rootScope . $digest ( ) ;
11239
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11240
- } ) ) ;
11246
+ function ( ) {
11247
+ $rootScope . test = 'TEST' ;
11248
+ element = $compile ( '<div async-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
11249
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11250
+ $rootScope . $digest ( ) ;
11251
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11252
+ }
11253
+ ) ;
11241
11254
11242
11255
it ( 'should provide post-digest value in asynchronous directive link functions when before overridden attribute' ,
11243
- inject ( function ( log , $rootScope , $compile ) {
11244
- $rootScope . test = 'TEST' ;
11245
- element = $compile ( '<div async-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
11246
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11247
- $rootScope . $digest ( ) ;
11248
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11249
- } ) ) ;
11256
+ function ( ) {
11257
+ $rootScope . test = 'TEST' ;
11258
+ element = $compile ( '<div async-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
11259
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11260
+ $rootScope . $digest ( ) ;
11261
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11262
+ }
11263
+ ) ;
11250
11264
} ) ;
11251
11265
11252
- it ( 'should work with different prefixes' , inject ( function ( $compile , $rootScope ) {
11266
+ it ( 'should work with different prefixes' , inject ( function ( ) {
11253
11267
$rootScope . name = 'Misko' ;
11254
11268
element = $compile ( '<span ng:attr:test="{{name}}" ng-Attr-test2="{{name}}" ng_Attr_test3="{{name}}"></span>' ) ( $rootScope ) ;
11255
11269
expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
@@ -11261,14 +11275,14 @@ describe('$compile', function() {
11261
11275
expect ( element . attr ( 'test3' ) ) . toBe ( 'Misko' ) ;
11262
11276
} ) ) ;
11263
11277
11264
- it ( 'should work with the "href" attribute' , inject ( function ( $compile , $rootScope ) {
11278
+ it ( 'should work with the "href" attribute' , inject ( function ( ) {
11265
11279
$rootScope . value = 'test' ;
11266
11280
element = $compile ( '<a ng-attr-href="test/{{value}}"></a>' ) ( $rootScope ) ;
11267
11281
$rootScope . $digest ( ) ;
11268
11282
expect ( element . attr ( 'href' ) ) . toBe ( 'test/test' ) ;
11269
11283
} ) ) ;
11270
11284
11271
- it ( 'should work if they are prefixed with x- or data- and different prefixes' , inject ( function ( $compile , $rootScope ) {
11285
+ it ( 'should work if they are prefixed with x- or data- and different prefixes' , inject ( function ( ) {
11272
11286
$rootScope . name = 'Misko' ;
11273
11287
element = $compile ( '<span data-ng-attr-test2="{{name}}" x-ng-attr-test3="{{name}}" data-ng:attr-test4="{{name}}" ' +
11274
11288
'x_ng-attr-test5="{{name}}" data:ng-attr-test6="{{name}}"></span>' ) ( $rootScope ) ;
@@ -11286,8 +11300,7 @@ describe('$compile', function() {
11286
11300
} ) ) ;
11287
11301
11288
11302
describe ( 'when an attribute has a dash-separated name' , function ( ) {
11289
-
11290
- it ( 'should work with different prefixes' , inject ( function ( $compile , $rootScope ) {
11303
+ it ( 'should work with different prefixes' , inject ( function ( ) {
11291
11304
$rootScope . name = 'JamieMason' ;
11292
11305
element = $compile ( '<span ng:attr:dash-test="{{name}}" ng-Attr-dash-test2="{{name}}" ng_Attr_dash-test3="{{name}}"></span>' ) ( $rootScope ) ;
11293
11306
expect ( element . attr ( 'dash-test' ) ) . toBeUndefined ( ) ;
@@ -11299,7 +11312,7 @@ describe('$compile', function() {
11299
11312
expect ( element . attr ( 'dash-test3' ) ) . toBe ( 'JamieMason' ) ;
11300
11313
} ) ) ;
11301
11314
11302
- it ( 'should work if they are prefixed with x- or data-' , inject ( function ( $compile , $rootScope ) {
11315
+ it ( 'should work if they are prefixed with x- or data-' , inject ( function ( ) {
11303
11316
$rootScope . name = 'JamieMason' ;
11304
11317
element = $compile ( '<span data-ng-attr-dash-test2="{{name}}" x-ng-attr-dash-test3="{{name}}" data-ng:attr-dash-test4="{{name}}"></span>' ) ( $rootScope ) ;
11305
11318
expect ( element . attr ( 'dash-test2' ) ) . toBeUndefined ( ) ;
@@ -11328,7 +11341,6 @@ describe('$compile', function() {
11328
11341
} ) ;
11329
11342
} ) ;
11330
11343
11331
-
11332
11344
it ( 'should keep attributes ending with -end single-element directives' , function ( ) {
11333
11345
module ( function ( $compileProvider ) {
11334
11346
$compileProvider . directive ( 'dashEnder' , function ( log ) {
@@ -11346,7 +11358,6 @@ describe('$compile', function() {
11346
11358
} ) ;
11347
11359
} ) ;
11348
11360
} ) ;
11349
-
11350
11361
} ) ;
11351
11362
11352
11363
0 commit comments