@@ -169,6 +169,15 @@ describe('$compile', function() {
169
169
inject ( ) ;
170
170
} ) ;
171
171
172
+ it ( 'should allow strictComponentBindingsEnabled to be configured' , function ( ) {
173
+ module ( function ( $compileProvider ) {
174
+ expect ( $compileProvider . strictComponentBindingsEnabled ( ) ) . toBe ( false ) ; // the default
175
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
176
+ expect ( $compileProvider . strictComponentBindingsEnabled ( ) ) . toBe ( true ) ;
177
+ } ) ;
178
+ inject ( ) ;
179
+ } ) ;
180
+
172
181
it ( 'should allow onChangesTtl to be configured' , function ( ) {
173
182
module ( function ( $compileProvider ) {
174
183
expect ( $compileProvider . onChangesTtl ( ) ) . toBe ( 10 ) ; // the default
@@ -2546,6 +2555,52 @@ describe('$compile', function() {
2546
2555
template : '<span></span>'
2547
2556
} ;
2548
2557
} ) ;
2558
+ directive ( 'prototypeMethodNameAsScopeVarD' , function ( ) {
2559
+ return {
2560
+ scope : {
2561
+ 'constructor' : '<?' ,
2562
+ 'valueOf' : '<'
2563
+ } ,
2564
+ restrict : 'AE' ,
2565
+ template : '<span></span>'
2566
+ } ;
2567
+ } ) ;
2568
+ directive ( 'optionalBindingsVarA' , function ( ) {
2569
+ return {
2570
+ scope : {
2571
+ 'variable' : '=?'
2572
+ } ,
2573
+ restrict : 'AE' ,
2574
+ template : '<span></span>'
2575
+ } ;
2576
+ } ) ;
2577
+ directive ( 'optionalBindingsVarB' , function ( ) {
2578
+ return {
2579
+ scope : {
2580
+ 'variable' : '@?'
2581
+ } ,
2582
+ restrict : 'AE' ,
2583
+ template : '<span></span>'
2584
+ } ;
2585
+ } ) ;
2586
+ directive ( 'optionalBindingsVarC' , function ( ) {
2587
+ return {
2588
+ scope : {
2589
+ 'variable' : '&?'
2590
+ } ,
2591
+ restrict : 'AE' ,
2592
+ template : '<span></span>'
2593
+ } ;
2594
+ } ) ;
2595
+ directive ( 'optionalBindingsVarD' , function ( ) {
2596
+ return {
2597
+ scope : {
2598
+ 'variable' : '<?'
2599
+ } ,
2600
+ restrict : 'AE' ,
2601
+ template : '<span></span>'
2602
+ } ;
2603
+ } ) ;
2549
2604
directive ( 'watchAsScopeVar' , function ( ) {
2550
2605
return {
2551
2606
scope : {
@@ -2854,6 +2909,39 @@ describe('$compile', function() {
2854
2909
} )
2855
2910
) ;
2856
2911
2912
+ it ( 'should throw an error for undefined non-optional "=" bindings when ' +
2913
+ 'strictComponentBindingsEnabled is true' , function ( ) {
2914
+ module ( function ( $compileProvider ) {
2915
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
2916
+ } ) ;
2917
+ inject (
2918
+ function ( $rootScope , $compile ) {
2919
+ var func = function ( ) {
2920
+ element = $compile (
2921
+ '<div prototype-method-name-as-scope-var-a></div>'
2922
+ ) ( $rootScope ) ;
2923
+ } ;
2924
+ expect ( func ) . toThrowMinErr ( '$compile' ,
2925
+ 'missingattr' ,
2926
+ 'Attribute \'valueOf\' of \'prototypeMethodNameAs' +
2927
+ 'ScopeVarA\' is non-optional and must be set!' ) ;
2928
+ } ) ;
2929
+ } ) ;
2930
+
2931
+ it ( 'should handle "=" undefined optional bindings when strictComponentBindingsEnabled is true' ,
2932
+ function ( ) {
2933
+ module ( function ( $compileProvider ) {
2934
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
2935
+ } ) ;
2936
+ inject (
2937
+ function ( $rootScope , $compile ) {
2938
+ var func = function ( ) {
2939
+ element = $compile ( '<div optional-bindings-var-a></div>' ) ( $rootScope ) ;
2940
+ } ;
2941
+ expect ( func ) . not . toThrow ( ) ;
2942
+ } ) ;
2943
+ } ) ;
2944
+
2857
2945
it ( 'should handle "@" bindings with same method names in Object.prototype correctly when not present' , inject (
2858
2946
function ( $rootScope , $compile ) {
2859
2947
var func = function ( ) {
@@ -2891,6 +2979,39 @@ describe('$compile', function() {
2891
2979
} )
2892
2980
) ;
2893
2981
2982
+ it ( 'should throw an error for undefined non-optional "@" bindings when ' +
2983
+ 'strictComponentBindingsEnabled is true' , function ( ) {
2984
+ module ( function ( $compileProvider ) {
2985
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
2986
+ } ) ;
2987
+ inject (
2988
+ function ( $rootScope , $compile ) {
2989
+ var func = function ( ) {
2990
+ element = $compile (
2991
+ '<div prototype-method-name-as-scope-var-b></div>'
2992
+ ) ( $rootScope ) ;
2993
+ } ;
2994
+ expect ( func ) . toThrowMinErr ( '$compile' ,
2995
+ 'missingattr' ,
2996
+ 'Attribute \'valueOf\' of \'prototypeMethodNameAs' +
2997
+ 'ScopeVarB\' is non-optional and must be set!' ) ;
2998
+ } ) ;
2999
+ } ) ;
3000
+
3001
+ it ( 'should handle "@" undefined optional bindings when strictComponentBindingsEnabled is true' ,
3002
+ function ( ) {
3003
+ module ( function ( $compileProvider ) {
3004
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
3005
+ } ) ;
3006
+ inject (
3007
+ function ( $rootScope , $compile ) {
3008
+ var func = function ( ) {
3009
+ element = $compile ( '<div optional-bindings-var-b></div>' ) ( $rootScope ) ;
3010
+ } ;
3011
+ expect ( func ) . not . toThrow ( ) ;
3012
+ } ) ;
3013
+ } ) ;
3014
+
2894
3015
it ( 'should handle "&" bindings with same method names in Object.prototype correctly when not present' , inject (
2895
3016
function ( $rootScope , $compile ) {
2896
3017
var func = function ( ) {
@@ -2923,6 +3044,72 @@ describe('$compile', function() {
2923
3044
} )
2924
3045
) ;
2925
3046
3047
+ it ( 'should throw an error for undefined non-optional "&" bindings when ' +
3048
+ 'strictComponentBindingsEnabled is true' , function ( ) {
3049
+ module ( function ( $compileProvider ) {
3050
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
3051
+ } ) ;
3052
+ inject (
3053
+ function ( $rootScope , $compile ) {
3054
+ var func = function ( ) {
3055
+ element = $compile (
3056
+ '<div prototype-method-name-as-scope-var-c></div>'
3057
+ ) ( $rootScope ) ;
3058
+ } ;
3059
+ expect ( func ) . toThrowMinErr ( '$compile' ,
3060
+ 'missingattr' ,
3061
+ 'Attribute \'valueOf\' of \'prototypeMethodNameAs' +
3062
+ 'ScopeVarC\' is non-optional and must be set!' ) ;
3063
+ } ) ;
3064
+ } ) ;
3065
+
3066
+ it ( 'should handle "&" undefined optional bindings when strictComponentBindingsEnabled is true' ,
3067
+ function ( ) {
3068
+ module ( function ( $compileProvider ) {
3069
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
3070
+ } ) ;
3071
+ inject (
3072
+ function ( $rootScope , $compile ) {
3073
+ var func = function ( ) {
3074
+ element = $compile ( '<div optional-bindings-var-c></div>' ) ( $rootScope ) ;
3075
+ } ;
3076
+ expect ( func ) . not . toThrow ( ) ;
3077
+ } ) ;
3078
+ } ) ;
3079
+
3080
+ it ( 'should throw an error for undefined non-optional ">" bindings when ' +
3081
+ 'strictComponentBindingsEnabled is true' , function ( ) {
3082
+ module ( function ( $compileProvider ) {
3083
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
3084
+ } ) ;
3085
+ inject (
3086
+ function ( $rootScope , $compile ) {
3087
+ var func = function ( ) {
3088
+ element = $compile (
3089
+ '<div prototype-method-name-as-scope-var-d></div>'
3090
+ ) ( $rootScope ) ;
3091
+ } ;
3092
+ expect ( func ) . toThrowMinErr ( '$compile' ,
3093
+ 'missingattr' ,
3094
+ 'Attribute \'valueOf\' of \'prototypeMethodNameAs' +
3095
+ 'ScopeVarD\' is non-optional and must be set!' ) ;
3096
+ } ) ;
3097
+ } ) ;
3098
+
3099
+ it ( 'should handle ">" undefined optional bindings when strictComponentBindingsEnabled is true' ,
3100
+ function ( ) {
3101
+ module ( function ( $compileProvider ) {
3102
+ $compileProvider . strictComponentBindingsEnabled ( true ) ;
3103
+ } ) ;
3104
+ inject (
3105
+ function ( $rootScope , $compile ) {
3106
+ var func = function ( ) {
3107
+ element = $compile ( '<div optional-bindings-var-d></div>' ) ( $rootScope ) ;
3108
+ } ;
3109
+ expect ( func ) . not . toThrow ( ) ;
3110
+ } ) ;
3111
+ } ) ;
3112
+
2926
3113
it ( 'should not throw exception when using "watch" as binding in Firefox' , inject (
2927
3114
function ( $rootScope , $compile ) {
2928
3115
$rootScope . watch = 'watch' ;
0 commit comments