diff options
Diffstat (limited to 'test/ng')
| -rwxr-xr-x | test/ng/compileSpec.js | 9 | ||||
| -rw-r--r-- | test/ng/controllerSpec.js | 7 | ||||
| -rw-r--r-- | test/ng/directive/formSpec.js | 12 | ||||
| -rw-r--r-- | test/ng/directive/ngRepeatSpec.js | 8 | ||||
| -rw-r--r-- | test/ng/directive/selectSpec.js | 10 | ||||
| -rw-r--r-- | test/ng/parseSpec.js | 20 |
6 files changed, 66 insertions, 0 deletions
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 5e28c62b..1e6f6e26 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -117,6 +117,15 @@ describe('$compile', function() { expect(log).toEqual('pre1; pre2; post2; post1'); }); }); + + it('should throw an exception if a directive is called "hasOwnProperty"', function() { + module(function() { + expect(function() { + directive('hasOwnProperty', function() { }); + }).toThrowMinErr('ng','badname', "hasOwnProperty is not a valid directive name"); + }); + inject(function($compile) {}); + }); }); diff --git a/test/ng/controllerSpec.js b/test/ng/controllerSpec.js index 2a9922c6..4f94402f 100644 --- a/test/ng/controllerSpec.js +++ b/test/ng/controllerSpec.js @@ -57,6 +57,13 @@ describe('$controller', function() { expect(scope.foo).toBe('bar'); expect(ctrl instanceof FooCtrl).toBe(true); }); + + + it('should throw an exception if a controller is called "hasOwnProperty"', function () { + expect(function() { + $controllerProvider.register('hasOwnProperty', function($scope) {}); + }).toThrowMinErr('ng', 'badname', "hasOwnProperty is not a valid controller name"); + }); }); diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index fb64fdb3..53fd3d90 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -137,6 +137,18 @@ describe('form', function() { }); + it('should throw an exception if an input has name="hasOwnProperty"', function() { + doc = jqLite( + '<form name="form">'+ + '<input name="hasOwnProperty" ng-model="some" />'+ + '<input name="other" ng-model="someOther" />'+ + '</form>'); + expect(function() { + $compile(doc)(scope); + }).toThrowMinErr('ng', 'badname'); + }); + + describe('preventing default submission', function() { it('should prevent form submission', function() { diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 72035566..4cf79dbf 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -137,6 +137,14 @@ describe('ngRepeat', function() { }); + it("should throw an exception if 'track by' evaluates to 'hasOwnProperty'", function() { + scope.items = {age:20}; + $compile('<div ng-repeat="(key, value) in items track by \'hasOwnProperty\'"></div>')(scope); + scope.$digest(); + expect($exceptionHandler.errors.shift().message).toMatch(/ng:badname/); + }); + + it('should track using build in $id function', function() { element = $compile( '<ul>' + diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 584fe614..85acba19 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -1247,5 +1247,15 @@ describe('select', function() { expect(element.find('span').text()).toBe('success'); dealoc(element); })); + + it('should throw an exception if an option value interpolates to "hasOwnProperty"', function() { + scope.hasOwnPropertyOption = "hasOwnProperty"; + expect(function() { + compile('<select ng-model="x">'+ + '<option>{{hasOwnPropertyOption}}</option>'+ + '</select>'); + }).toThrowMinErr('ng','badname', 'hasOwnProperty is not a valid "option value" name'); + }); + }); }); diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 87cc79af..19182332 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -351,6 +351,26 @@ describe('parser', function() { expect(scope.$eval('toString()', scope)).toBe('custom toString'); }); + it('should not break if hasOwnProperty is referenced in an expression', function() { + scope.obj = { value: 1}; + // By evaluating an expression that calls hasOwnProperty, the getterFnCache + // will store a property called hasOwnProperty. This is effectively: + // getterFnCache['hasOwnProperty'] = null + scope.$eval('obj.hasOwnProperty("value")'); + // If we rely on this property then evaluating any expression will fail + // because it is not able to find out if obj.value is there in the cache + expect(scope.$eval('obj.value')).toBe(1); + }); + + it('should not break if the expression is "hasOwnProperty"', function() { + scope.fooExp = 'barVal'; + // By evaluating hasOwnProperty, the $parse cache will store a getter for + // the scope's own hasOwnProperty function, which will mess up future cache look ups. + // i.e. cache['hasOwnProperty'] = function(scope) { return scope.hasOwnProperty; } + scope.$eval('hasOwnProperty'); + expect(scope.$eval('fooExp')).toBe('barVal'); + }); + it('should evaluate grouped expressions', function() { expect(scope.$eval("(1+2)*3")).toEqual((1+2)*3); }); |
