Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit cd5c3d7

Browse files
committed
more tests
1 parent 761876f commit cd5c3d7

File tree

1 file changed

+110
-2
lines changed

1 file changed

+110
-2
lines changed

test/ng/parseSpec.js

+110-2
Original file line numberDiff line numberDiff line change
@@ -3070,6 +3070,29 @@ describe('parser', function() {
30703070
expect(watcherCalls).toBe(2);
30713071
}));
30723072

3073+
it('should not reevaluate filters within literals with primitive inputs', inject(function($parse) {
3074+
var filterCalls = 0;
3075+
$filterProvider.register('foo', valueFn(function(input) {
3076+
filterCalls++;
3077+
return input;
3078+
}));
3079+
3080+
scope.prim = 1234567890123;
3081+
3082+
var watcherCalls = 0;
3083+
scope.$watch('[(prim | foo)]', function(input) {
3084+
watcherCalls++;
3085+
});
3086+
3087+
scope.$digest();
3088+
expect(filterCalls).toBe(1);
3089+
expect(watcherCalls).toBe(1);
3090+
3091+
scope.$digest();
3092+
expect(filterCalls).toBe(1);
3093+
expect(watcherCalls).toBe(1);
3094+
}));
3095+
30733096
it('should always reevaluate filters with non-primitive inputs within literals',
30743097
inject(function($parse) {
30753098
$filterProvider.register('foo', valueFn(function(input) {
@@ -3078,7 +3101,7 @@ describe('parser', function() {
30783101

30793102
scope.$watch('[(a | foo)]', function() {});
30803103

3081-
// Would be great if this didn't throw...
3104+
// Would be great if filter-output was checked for changes and this didn't throw...
30823105
expect(function() { scope.$apply('a = {b: 1}'); }).toThrowMinErr('$rootScope', 'infdig');
30833106
}));
30843107

@@ -3088,7 +3111,7 @@ describe('parser', function() {
30883111

30893112
scope.$apply('a = 1');
30903113

3091-
// Would be great if this didn't throw...
3114+
// Would be great if filter-output was checked for changes and this didn't throw...
30923115
expect(function() { scope.$apply('a = {}'); }).toThrowMinErr('$rootScope', 'infdig');
30933116
}));
30943117

@@ -3116,6 +3139,30 @@ describe('parser', function() {
31163139
expect(watcherCalls).toBe(1);
31173140
}));
31183141

3142+
it('should not reevaluate filters with non-primitive input that gets simplified via non plus/concat binary operators',
3143+
inject(function($parse) {
3144+
var filterCalls = 0;
3145+
$filterProvider.register('foo', valueFn(function(input) {
3146+
filterCalls++;
3147+
return input;
3148+
}));
3149+
3150+
scope.obj = {};
3151+
3152+
var watcherCalls = 0;
3153+
scope.$watch('1 - obj | foo:(1 * obj)', function(input) {
3154+
watcherCalls++;
3155+
});
3156+
3157+
scope.$digest();
3158+
expect(filterCalls).toBe(1);
3159+
expect(watcherCalls).toBe(1);
3160+
3161+
scope.$digest();
3162+
expect(filterCalls).toBe(1);
3163+
expect(watcherCalls).toBe(1);
3164+
}));
3165+
31193166
it('should reevaluate filters with non-primitive input that gets simplified via plus/concat', inject(function($parse) {
31203167
var filterCalls = 0;
31213168
$filterProvider.register('foo', valueFn(function(input) {
@@ -3139,6 +3186,31 @@ describe('parser', function() {
31393186
expect(watcherCalls).toBe(1);
31403187
}));
31413188

3189+
it('should reevaluate computed member expressions with non-primitive input', inject(function($parse) {
3190+
var toStringCalls = 0;
3191+
3192+
scope.obj = {};
3193+
scope.key = {
3194+
toString: function() {
3195+
toStringCalls++;
3196+
return 'foo';
3197+
}
3198+
};
3199+
3200+
var watcherCalls = 0;
3201+
scope.$watch('obj[key]', function(input) {
3202+
watcherCalls++;
3203+
});
3204+
3205+
scope.$digest();
3206+
expect(toStringCalls).toBe(2);
3207+
expect(watcherCalls).toBe(1);
3208+
3209+
scope.$digest();
3210+
expect(toStringCalls).toBe(3);
3211+
expect(watcherCalls).toBe(1);
3212+
}));
3213+
31423214
it('should always reevaluate filters with non-primitive input created with null prototype',
31433215
inject(function($parse) {
31443216
var filterCalls = 0;
@@ -3244,6 +3316,23 @@ describe('parser', function() {
32443316
expect(called).toBe(true);
32453317
}));
32463318

3319+
it('should not reevaluate literals with non-primitive input', inject(function($parse) {
3320+
var obj = scope.obj = {};
3321+
3322+
var parsed = $parse('[obj]');
3323+
var watcherCalls = 0;
3324+
scope.$watch(parsed, function(input) {
3325+
expect(input[0]).toBe(obj);
3326+
watcherCalls++;
3327+
});
3328+
3329+
scope.$digest();
3330+
expect(watcherCalls).toBe(1);
3331+
3332+
scope.$digest();
3333+
expect(watcherCalls).toBe(1);
3334+
}));
3335+
32473336
it('should not reevaluate literals with non-primitive input that does support valueOf()',
32483337
inject(function($parse) {
32493338

@@ -3263,6 +3352,25 @@ describe('parser', function() {
32633352
expect(watcherCalls).toBe(1);
32643353
}));
32653354

3355+
it('should reevaluate literals with non-primitive input when valueOf() changes', inject(function($parse) {
3356+
var date = scope.date = new Date();
3357+
3358+
var parsed = $parse('[date]');
3359+
var watcherCalls = 0;
3360+
scope.$watch(parsed, function(input) {
3361+
expect(input[0]).toBe(date);
3362+
watcherCalls++;
3363+
});
3364+
3365+
scope.$digest();
3366+
expect(watcherCalls).toBe(1);
3367+
3368+
date.setYear(1901);
3369+
3370+
scope.$digest();
3371+
expect(watcherCalls).toBe(2);
3372+
}));
3373+
32663374
it('should not reevaluate literals with non-primitive input that does support valueOf()' +
32673375
' when the instance changes but valueOf() does not', inject(function($parse) {
32683376

0 commit comments

Comments
 (0)