@@ -4901,6 +4901,83 @@ describe('$compile', function() {
4901
4901
expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
4902
4902
} ) ) ;
4903
4903
4904
+ it ( 'should bind after digest but not before when after overridden attribute' , inject ( function ( $compile , $rootScope ) {
4905
+ $rootScope . name = "Misko" ;
4906
+ element = $compile ( '<span test="123" ng-attr-test="{{name}}"></span>' ) ( $rootScope ) ;
4907
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
4908
+ $rootScope . $digest ( ) ;
4909
+ expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
4910
+ } ) ) ;
4911
+
4912
+ it ( 'should bind after digest but not before when before overridden attribute' , inject ( function ( $compile , $rootScope ) {
4913
+ $rootScope . name = "Misko" ;
4914
+ element = $compile ( '<span ng-attr-test="{{name}}" test="123"></span>' ) ( $rootScope ) ;
4915
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
4916
+ $rootScope . $digest ( ) ;
4917
+ expect ( element . attr ( 'test' ) ) . toBe ( 'Misko' ) ;
4918
+ } ) ) ;
4919
+
4920
+
4921
+ describe ( 'in directive' , function ( ) {
4922
+ beforeEach ( module ( function ( ) {
4923
+ directive ( 'syncTest' , function ( log ) {
4924
+ return {
4925
+ link : {
4926
+ pre : function ( s , e , attr ) { log ( attr . test ) ; } ,
4927
+ post : function ( s , e , attr ) { log ( attr . test ) ; }
4928
+ }
4929
+ } ;
4930
+ } ) ;
4931
+ directive ( 'asyncTest' , function ( log ) {
4932
+ return {
4933
+ templateUrl : 'async.html' ,
4934
+ link : {
4935
+ pre : function ( s , e , attr ) { log ( attr . test ) ; } ,
4936
+ post : function ( s , e , attr ) { log ( attr . test ) ; }
4937
+ }
4938
+ } ;
4939
+ } ) ;
4940
+ } ) ) ;
4941
+
4942
+ beforeEach ( inject ( function ( $templateCache ) {
4943
+ $templateCache . put ( 'async.html' , '<h1>Test</h1>' ) ;
4944
+ } ) ) ;
4945
+
4946
+ it ( 'should provide post-digest value in synchronous directive link functions when after overridden attribute' ,
4947
+ inject ( function ( log , $rootScope , $compile ) {
4948
+ $rootScope . test = "TEST" ;
4949
+ element = $compile ( '<div sync-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
4950
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
4951
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
4952
+ } ) ) ;
4953
+
4954
+ it ( 'should provide post-digest value in synchronous directive link functions when before overridden attribute' ,
4955
+ inject ( function ( log , $rootScope , $compile ) {
4956
+ $rootScope . test = "TEST" ;
4957
+ element = $compile ( '<div sync-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
4958
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
4959
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
4960
+ } ) ) ;
4961
+
4962
+
4963
+ it ( 'should provide post-digest value in asynchronous directive link functions when after overridden attribute' ,
4964
+ inject ( function ( log , $rootScope , $compile ) {
4965
+ $rootScope . test = "TEST" ;
4966
+ element = $compile ( '<div async-test test="123" ng-attr-test="{{test}}"></div>' ) ( $rootScope ) ;
4967
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
4968
+ $rootScope . $digest ( ) ;
4969
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
4970
+ } ) ) ;
4971
+
4972
+ it ( 'should provide post-digest value in asynchronous directive link functions when before overridden attribute' ,
4973
+ inject ( function ( log , $rootScope , $compile ) {
4974
+ $rootScope . test = "TEST" ;
4975
+ element = $compile ( '<div async-test ng-attr-test="{{test}}" test="123"></div>' ) ( $rootScope ) ;
4976
+ expect ( element . attr ( 'test' ) ) . toBe ( '123' ) ;
4977
+ $rootScope . $digest ( ) ;
4978
+ expect ( log . toArray ( ) ) . toEqual ( [ 'TEST' , 'TEST' ] ) ;
4979
+ } ) ) ;
4980
+ } ) ;
4904
4981
4905
4982
it ( 'should work with different prefixes' , inject ( function ( $compile , $rootScope ) {
4906
4983
$rootScope . name = "Misko" ;
0 commit comments