@@ -3233,8 +3233,7 @@ describe('parser', function() {
3233
3233
3234
3234
describe ( 'interceptorFns' , function ( ) {
3235
3235
3236
- it ( 'should always be invoked if they are flagged as having $stateful' ,
3237
- inject ( function ( $parse ) {
3236
+ it ( 'should always be invoked if flagged as $stateful' , inject ( function ( $parse ) {
3238
3237
var called = false ;
3239
3238
function interceptor ( ) {
3240
3239
called = true ;
@@ -3256,6 +3255,72 @@ describe('parser', function() {
3256
3255
expect ( called ) . toBe ( true ) ;
3257
3256
} ) ) ;
3258
3257
3258
+ it ( 'should always be invoked if flagged as $stateful when wrapping one-time' ,
3259
+ inject ( function ( $parse ) {
3260
+
3261
+ var interceptorCalls = 0 ;
3262
+ function interceptor ( ) {
3263
+ interceptorCalls ++ ;
3264
+ return 123 ;
3265
+ }
3266
+ interceptor . $stateful = true ;
3267
+
3268
+ scope . $watch ( $parse ( '::a' , interceptor ) ) ;
3269
+
3270
+ interceptorCalls = 0 ;
3271
+ scope . $digest ( ) ;
3272
+ expect ( interceptorCalls ) . not . toBe ( 0 ) ;
3273
+
3274
+ interceptorCalls = 0 ;
3275
+ scope . $digest ( ) ;
3276
+ expect ( interceptorCalls ) . not . toBe ( 0 ) ;
3277
+ } ) ) ;
3278
+
3279
+ it ( 'should always be invoked if flagged as $stateful when wrapping one-time with inputs' ,
3280
+ inject ( function ( $parse ) {
3281
+
3282
+ $filterProvider . register ( 'identity' , valueFn ( identity ) ) ;
3283
+
3284
+ var interceptorCalls = 0 ;
3285
+ function interceptor ( ) {
3286
+ interceptorCalls ++ ;
3287
+ return 123 ;
3288
+ }
3289
+ interceptor . $stateful = true ;
3290
+
3291
+ scope . $watch ( $parse ( '::a | identity' , interceptor ) ) ;
3292
+
3293
+ interceptorCalls = 0 ;
3294
+ scope . $digest ( ) ;
3295
+ expect ( interceptorCalls ) . not . toBe ( 0 ) ;
3296
+
3297
+ interceptorCalls = 0 ;
3298
+ scope . $digest ( ) ;
3299
+ expect ( interceptorCalls ) . not . toBe ( 0 ) ;
3300
+ } ) ) ;
3301
+
3302
+ it ( 'should always be invoked if flagged as $stateful when wrapping one-time literal' ,
3303
+ inject ( function ( $parse ) {
3304
+
3305
+ var interceptorCalls = 0 ;
3306
+ function interceptor ( ) {
3307
+ interceptorCalls ++ ;
3308
+ return 123 ;
3309
+ }
3310
+ interceptor . $stateful = true ;
3311
+
3312
+ scope . $watch ( $parse ( '::[a]' , interceptor ) ) ;
3313
+
3314
+ // Would be great if interceptor-output was checked for changes and this didn't throw...
3315
+ interceptorCalls = 0 ;
3316
+ expect ( function ( ) { scope . $digest ( ) ; } ) . toThrowMinErr ( '$rootScope' , 'infdig' ) ;
3317
+ expect ( interceptorCalls ) . not . toBe ( 0 ) ;
3318
+
3319
+ interceptorCalls = 0 ;
3320
+ expect ( function ( ) { scope . $digest ( ) ; } ) . toThrowMinErr ( '$rootScope' , 'infdig' ) ;
3321
+ expect ( interceptorCalls ) . not . toBe ( 0 ) ;
3322
+ } ) ) ;
3323
+
3259
3324
it ( 'should not be invoked unless the input changes' , inject ( function ( $parse ) {
3260
3325
var called = false ;
3261
3326
function interceptor ( v ) {
@@ -3321,6 +3386,29 @@ describe('parser', function() {
3321
3386
scope . $digest ( ) ;
3322
3387
expect ( called ) . toBe ( true ) ;
3323
3388
} ) ) ;
3389
+
3390
+ it ( 'should not propogate $$watchDelegate to the interceptor wrapped expression' , inject ( function ( $parse ) {
3391
+ function getter ( s ) {
3392
+ return s . x ;
3393
+ }
3394
+ getter . $$watchDelegate = getter ;
3395
+
3396
+ function doubler ( v ) {
3397
+ return 2 * v ;
3398
+ }
3399
+
3400
+ var lastValue ;
3401
+ function watcher ( val ) {
3402
+ lastValue = val ;
3403
+ }
3404
+ scope . $watch ( $parse ( getter , doubler ) , watcher ) ;
3405
+
3406
+ scope . $apply ( 'x = 1' ) ;
3407
+ expect ( lastValue ) . toBe ( 2 * 1 ) ;
3408
+
3409
+ scope . $apply ( 'x = 123' ) ;
3410
+ expect ( lastValue ) . toBe ( 2 * 123 ) ;
3411
+ } ) ) ;
3324
3412
} ) ;
3325
3413
3326
3414
describe ( 'literals' , function ( ) {
0 commit comments