From 935c1018da05dbf3124b2dd33619c4a3c82d7a2a Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sat, 17 Mar 2012 15:57:55 -0700 Subject: [PATCH] fix(ngRepeat): correct variable reference in error message Closese #803 --- src/directive/ngRepeat.js | 4 ++-- test/directive/ngRepeatSpec.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/directive/ngRepeat.js b/src/directive/ngRepeat.js index efa271530df9..82f8b9c734c1 100644 --- a/src/directive/ngRepeat.js +++ b/src/directive/ngRepeat.js @@ -73,10 +73,10 @@ var ngRepeatDirective = ngDirective({ } lhs = match[1]; rhs = match[2]; - match = lhs.match(/^([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\)$/); + match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); if (!match) { throw Error("'item' in 'item in collection' should be identifier or (key, value) but got '" + - keyValue + "'."); + lhs + "'."); } valueIdent = match[3] || match[1]; keyIdent = match[2]; diff --git a/test/directive/ngRepeatSpec.js b/test/directive/ngRepeatSpec.js index 8b6a5173bc68..85aa151140c7 100644 --- a/test/directive/ngRepeatSpec.js +++ b/test/directive/ngRepeatSpec.js @@ -64,12 +64,19 @@ describe('ng-repeat', function() { })); - it('should error on wrong parsing of ng-repeat', inject(function($rootScope, $compile, $log) { + it('should error on wrong parsing of ng-repeat', inject(function($rootScope, $compile) { expect(function() { element = $compile('')($rootScope); }).toThrow("Expected ng-repeat in form of '_item_ in _collection_' but got 'i dont parse'."); + })); + - $log.error.logs.shift(); + it("should throw error when left-hand-side of ng-repeat can't be parsed", inject( + function($rootScope, $compile) { + expect(function() { + element = $compile('')($rootScope); + }).toThrow("'item' in 'item in collection' should be identifier or (key, value) but got " + + "'i dont parse'."); }));