@@ -1309,7 +1309,7 @@ describe('parser', function() {
1309
1309
1310
1310
it ( 'should respect short-circuiting AND if it could have side effects' , function ( ) {
1311
1311
var bCalled = 0 ;
1312
- scope . b = function ( ) { bCalled ++ ; }
1312
+ scope . b = function ( ) { bCalled ++ ; } ;
1313
1313
1314
1314
scope . $watch ( "a && b()" ) ;
1315
1315
scope . $digest ( ) ;
@@ -1325,7 +1325,7 @@ describe('parser', function() {
1325
1325
1326
1326
it ( 'should respect short-circuiting OR if it could have side effects' , function ( ) {
1327
1327
var bCalled = false ;
1328
- scope . b = function ( ) { bCalled = true ; }
1328
+ scope . b = function ( ) { bCalled = true ; } ;
1329
1329
1330
1330
scope . $watch ( "a || b()" ) ;
1331
1331
scope . $digest ( ) ;
@@ -1408,42 +1408,72 @@ describe('parser', function() {
1408
1408
expect ( called ) . toBe ( true ) ;
1409
1409
} ) ) ;
1410
1410
1411
- it ( 'should invoke interceptorFns if the yare marked as having externalInput ' , inject ( function ( $parse ) {
1412
- var called = false ;
1413
- function interceptor ( ) {
1414
- called = true ;
1415
- }
1416
- interceptor . externalInput = true ;
1411
+ it ( 'should treat filters with constant input as constants ' , inject ( function ( $parse ) {
1412
+ var filterCalls = 0 ;
1413
+ $filterProvider . register ( 'foo' , valueFn ( function ( input ) {
1414
+ filterCalls ++ ;
1415
+ return input ;
1416
+ } ) ) ;
1417
1417
1418
- scope . $watch ( $parse ( "a" , interceptor ) ) ;
1419
- scope . a = 0 ;
1420
- scope . $digest ( ) ;
1421
- expect ( called ) . toBe ( true ) ;
1418
+ var parsed = $parse ( '{x: 1} | foo:1' ) ;
1419
+
1420
+ expect ( parsed . constant ) . toBe ( true ) ;
1421
+
1422
+ var watcherCalls = 0 ;
1423
+ scope . $watch ( parsed , function ( input ) {
1424
+ expect ( input ) . toEqual ( { x :1 } ) ;
1425
+ watcherCalls ++ ;
1426
+ } ) ;
1422
1427
1423
- called = false ;
1424
1428
scope . $digest ( ) ;
1425
- expect ( called ) . toBe ( true ) ;
1429
+ expect ( filterCalls ) . toBe ( 1 ) ;
1430
+ expect ( watcherCalls ) . toBe ( 1 ) ;
1426
1431
1427
- scope . a ++ ;
1428
- called = false ;
1429
1432
scope . $digest ( ) ;
1430
- expect ( called ) . toBe ( true ) ;
1433
+ expect ( filterCalls ) . toBe ( 1 ) ;
1434
+ expect ( watcherCalls ) . toBe ( 1 ) ;
1431
1435
} ) ) ;
1432
1436
1433
- it ( 'should treat filters with constant input as constants' , inject ( function ( $parse ) {
1437
+ it ( "should always reevaluate filters with non-primitive input that doesn't support valueOf()" ,
1438
+ inject ( function ( $parse ) {
1434
1439
var filterCalls = 0 ;
1435
1440
$filterProvider . register ( 'foo' , valueFn ( function ( input ) {
1436
1441
filterCalls ++ ;
1437
1442
return input ;
1438
1443
} ) ) ;
1439
1444
1440
- var parsed = $parse ( '{x: 1} | foo:1' ) ;
1445
+ var parsed = $parse ( 'obj | foo' ) ;
1446
+ var obj = scope . obj = { } ;
1441
1447
1442
- expect ( parsed . constant ) . toBe ( true ) ;
1448
+ var watcherCalls = 0 ;
1449
+ scope . $watch ( parsed , function ( input ) {
1450
+ expect ( input ) . toBe ( obj ) ;
1451
+ watcherCalls ++ ;
1452
+ } ) ;
1453
+
1454
+ scope . $digest ( ) ;
1455
+ expect ( filterCalls ) . toBe ( 2 ) ;
1456
+ expect ( watcherCalls ) . toBe ( 1 ) ;
1457
+
1458
+ scope . $digest ( ) ;
1459
+ expect ( filterCalls ) . toBe ( 3 ) ;
1460
+ expect ( watcherCalls ) . toBe ( 1 ) ;
1461
+ } ) ) ;
1462
+
1463
+ it ( "should not reevaluate filters with non-primitive input that does support valueOf()" ,
1464
+ inject ( function ( $parse ) {
1465
+ var filterCalls = 0 ;
1466
+ $filterProvider . register ( 'foo' , valueFn ( function ( input ) {
1467
+ filterCalls ++ ;
1468
+ return input ;
1469
+ } ) ) ;
1470
+
1471
+ var parsed = $parse ( 'date | foo' ) ;
1472
+ var date = scope . date = new Date ( ) ;
1443
1473
1444
1474
var watcherCalls = 0 ;
1445
1475
scope . $watch ( parsed , function ( input ) {
1446
- expect ( input ) . toEqual ( { x : 1 } ) ;
1476
+ expect ( input ) . toBe ( date ) ;
1447
1477
watcherCalls ++ ;
1448
1478
} ) ;
1449
1479
@@ -1455,6 +1485,29 @@ describe('parser', function() {
1455
1485
expect ( filterCalls ) . toBe ( 1 ) ;
1456
1486
expect ( watcherCalls ) . toBe ( 1 ) ;
1457
1487
} ) ) ;
1488
+
1489
+ it ( 'should invoke interceptorFns if they are flagged as having externalInput' ,
1490
+ inject ( function ( $parse ) {
1491
+ var called = false ;
1492
+ function interceptor ( ) {
1493
+ called = true ;
1494
+ }
1495
+ interceptor . externalInput = true ;
1496
+
1497
+ scope . $watch ( $parse ( "a" , interceptor ) ) ;
1498
+ scope . a = 0 ;
1499
+ scope . $digest ( ) ;
1500
+ expect ( called ) . toBe ( true ) ;
1501
+
1502
+ called = false ;
1503
+ scope . $digest ( ) ;
1504
+ expect ( called ) . toBe ( true ) ;
1505
+
1506
+ scope . a ++ ;
1507
+ called = false ;
1508
+ scope . $digest ( ) ;
1509
+ expect ( called ) . toBe ( true ) ;
1510
+ } ) ) ;
1458
1511
} ) ;
1459
1512
1460
1513
describe ( 'locals' , function ( ) {
0 commit comments