@@ -10911,32 +10911,39 @@ describe('$compile', function() {
10911
10911
}
10912
10912
10913
10913
describe ( 'ngAttr* attribute binding' , function ( ) {
10914
-
10915
- it ( 'should bind after digest but not before' , inject ( function ( $compile , $rootScope ) {
10914
+ it ( 'should bind after digest but not before' , inject ( function ( ) {
10916
10915
$rootScope . name = 'Misko' ;
10917
10916
element = $compile ( '<span ng-attr-test="{{name}}"></span>' ) ( $rootScope ) ;
10918
10917
expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
10919
10918
$rootScope . $digest ( ) ;
10920
10919
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
10921
10920
} ) ) ;
10922
10921
10923
- it ( 'should bind after digest but not before when after overridden attribute' , inject ( function ( $compile , $rootScope ) {
10922
+ it ( 'should bind after digest but not before when after overridden attribute' , inject ( function ( ) {
10924
10923
$rootScope . name = 'Misko' ;
10925
10924
element = $compile ( '<span test="123" ng-attr-test="{{name}}"></span>' ) ( $rootScope ) ;
10926
10925
expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
10927
10926
$rootScope . $digest ( ) ;
10928
10927
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
10929
10928
} ) ) ;
10930
10929
10931
- it ( 'should bind after digest but not before when before overridden attribute' , inject ( function ( $compile , $rootScope ) {
10930
+ it ( 'should bind after digest but not before when before overridden attribute' , inject ( function ( ) {
10932
10931
$rootScope . name = 'Misko' ;
10933
10932
element = $compile ( '<span ng-attr-test="{{name}}" test="123"></span>' ) ( $rootScope ) ;
10934
10933
expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
10935
10934
$rootScope . $digest ( ) ;
10936
10935
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
10937
10936
} ) ) ;
10938
10937
10939
- it ( 'should remove attribute if any bindings are undefined' , inject ( function ( $compile , $rootScope ) {
10938
+ it ( 'should set the attribute (after digest) even if there is no interpolation' , inject ( function ( ) {
10939
+ element = $compile ( '<span ng-attr-test="foo"></span>' ) ( $rootScope ) ;
10940
+ expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
10941
+
10942
+ $rootScope . $digest ( ) ;
10943
+ expect ( element . attr ( 'test' ) ) . toBe ( 'foo' ) ;
10944
+ } ) ) ;
10945
+
10946
+ it ( 'should remove attribute if any bindings are undefined' , inject ( function ( ) {
10940
10947
element = $compile ( '<span ng-attr-test="{{name}}{{emphasis}}"></span>' ) ( $rootScope ) ;
10941
10948
$rootScope . $digest ( ) ;
10942
10949
expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
@@ -10949,6 +10956,8 @@ describe('$compile', function() {
10949
10956
} ) ) ;
10950
10957
10951
10958
describe ( 'in directive' , function ( ) {
10959
+ var log ;
10960
+
10952
10961
beforeEach ( module ( function ( ) {
10953
10962
directive ( 'syncTest' , function ( log ) {
10954
10963
return {
@@ -10969,47 +10978,52 @@ describe('$compile', function() {
10969
10978
} ) ;
10970
10979
} ) ) ;
10971
10980
10972
- beforeEach ( inject ( function ( $templateCache ) {
10981
+ beforeEach ( inject ( function ( $templateCache , _log_ ) {
10982
+ log = _log_ ;
10973
10983
$templateCache . put ( 'async.html' , '<h1>Test</h1>' ) ;
10974
10984
} ) ) ;
10975
10985
10976
10986
it ( 'should provide post-digest value in synchronous directive link functions when after overridden attribute' ,
10977
- inject ( function ( log , $rootScope , $compile ) {
10978
- $rootScope . test = 'TEST' ;
10979
- element = $compile ( '<div sync-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
10980
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
10981
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
10982
- } ) ) ;
10987
+ function ( ) {
10988
+ $rootScope . test = 'TEST' ;
10989
+ element = $compile ( '<div sync-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
10990
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
10991
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
10992
+ }
10993
+ ) ;
10983
10994
10984
10995
it ( 'should provide post-digest value in synchronous directive link functions when before overridden attribute' ,
10985
- inject ( function ( log , $rootScope , $compile ) {
10986
- $rootScope . test = 'TEST' ;
10987
- element = $compile ( '<div sync-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
10988
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
10989
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
10990
- } ) ) ;
10996
+ function ( ) {
10997
+ $rootScope . test = 'TEST' ;
10998
+ element = $compile ( '<div sync-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
10999
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11000
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11001
+ }
11002
+ ) ;
10991
11003
10992
11004
10993
11005
it ( 'should provide post-digest value in asynchronous directive link functions when after overridden attribute' ,
10994
- inject ( function ( log , $rootScope , $compile ) {
10995
- $rootScope . test = 'TEST' ;
10996
- element = $compile ( '<div async-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
10997
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
10998
- $rootScope . $digest ( ) ;
10999
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11000
- } ) ) ;
11006
+ function ( ) {
11007
+ $rootScope . test = 'TEST' ;
11008
+ element = $compile ( '<div async-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
11009
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11010
+ $rootScope . $digest ( ) ;
11011
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11012
+ }
11013
+ ) ;
11001
11014
11002
11015
it ( 'should provide post-digest value in asynchronous directive link functions when before overridden attribute' ,
11003
- inject ( function ( log , $rootScope , $compile ) {
11004
- $rootScope . test = 'TEST' ;
11005
- element = $compile ( '<div async-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
11006
- expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11007
- $rootScope . $digest ( ) ;
11008
- expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11009
- } ) ) ;
11016
+ function ( ) {
11017
+ $rootScope . test = 'TEST' ;
11018
+ element = $compile ( '<div async-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
11019
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
11020
+ $rootScope . $digest ( ) ;
11021
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
11022
+ }
11023
+ ) ;
11010
11024
} ) ;
11011
11025
11012
- it ( 'should work with different prefixes' , inject ( function ( $compile , $rootScope ) {
11026
+ it ( 'should work with different prefixes' , inject ( function ( ) {
11013
11027
$rootScope . name = 'Misko' ;
11014
11028
element = $compile ( '<span ng:attr:test="{{name}}" ng-Attr-test2="{{name}}" ng_Attr_test3="{{name}}"></span>' ) ( $rootScope ) ;
11015
11029
expect ( element . attr ( 'test' ) ) . toBeUndefined ( ) ;
@@ -11021,14 +11035,14 @@ describe('$compile', function() {
11021
11035
expect ( element . attr ( 'test3' ) ) . toBe ( 'Misko' ) ;
11022
11036
} ) ) ;
11023
11037
11024
- it ( 'should work with the "href" attribute' , inject ( function ( $compile , $rootScope ) {
11038
+ it ( 'should work with the "href" attribute' , inject ( function ( ) {
11025
11039
$rootScope . value = 'test' ;
11026
11040
element = $compile ( '<a ng-attr-href="test/{{value}}"></a>' ) ( $rootScope ) ;
11027
11041
$rootScope . $digest ( ) ;
11028
11042
expect ( element . attr ( 'href' ) ) . toBe ( 'test/test' ) ;
11029
11043
} ) ) ;
11030
11044
11031
- it ( 'should work if they are prefixed with x- or data- and different prefixes' , inject ( function ( $compile , $rootScope ) {
11045
+ it ( 'should work if they are prefixed with x- or data- and different prefixes' , inject ( function ( ) {
11032
11046
$rootScope . name = 'Misko' ;
11033
11047
element = $compile ( '<span data-ng-attr-test2="{{name}}" x-ng-attr-test3="{{name}}" data-ng:attr-test4="{{name}}" ' +
11034
11048
'x_ng-attr-test5="{{name}}" data:ng-attr-test6="{{name}}"></span>' ) ( $rootScope ) ;
@@ -11046,8 +11060,7 @@ describe('$compile', function() {
11046
11060
} ) ) ;
11047
11061
11048
11062
describe ( 'when an attribute has a dash-separated name' , function ( ) {
11049
-
11050
- it ( 'should work with different prefixes' , inject ( function ( $compile , $rootScope ) {
11063
+ it ( 'should work with different prefixes' , inject ( function ( ) {
11051
11064
$rootScope . name = 'JamieMason' ;
11052
11065
element = $compile ( '<span ng:attr:dash-test="{{name}}" ng-Attr-dash-test2="{{name}}" ng_Attr_dash-test3="{{name}}"></span>' ) ( $rootScope ) ;
11053
11066
expect ( element . attr ( 'dash-test' ) ) . toBeUndefined ( ) ;
@@ -11059,7 +11072,7 @@ describe('$compile', function() {
11059
11072
expect ( element . attr ( 'dash-test3' ) ) . toBe ( 'JamieMason' ) ;
11060
11073
} ) ) ;
11061
11074
11062
- it ( 'should work if they are prefixed with x- or data-' , inject ( function ( $compile , $rootScope ) {
11075
+ it ( 'should work if they are prefixed with x- or data-' , inject ( function ( ) {
11063
11076
$rootScope . name = 'JamieMason' ;
11064
11077
element = $compile ( '<span data-ng-attr-dash-test2="{{name}}" x-ng-attr-dash-test3="{{name}}" data-ng:attr-dash-test4="{{name}}"></span>' ) ( $rootScope ) ;
11065
11078
expect ( element . attr ( 'dash-test2' ) ) . toBeUndefined ( ) ;
@@ -11088,7 +11101,6 @@ describe('$compile', function() {
11088
11101
} ) ;
11089
11102
} ) ;
11090
11103
11091
-
11092
11104
it ( 'should keep attributes ending with -end single-element directives' , function ( ) {
11093
11105
module ( function ( $compileProvider ) {
11094
11106
$compileProvider . directive ( 'dashEnder' , function ( log ) {
@@ -11106,7 +11118,6 @@ describe('$compile', function() {
11106
11118
} ) ;
11107
11119
} ) ;
11108
11120
} ) ;
11109
-
11110
11121
} ) ;
11111
11122
11112
11123
0 commit comments