From 003861d2fdb37b83e1d0939d49b70fbc67766997 Mon Sep 17 00:00:00 2001 From: Ken Sheedlo Date: Fri, 7 Jun 2013 18:24:30 -0700 Subject: chore(minErr): replace ngError with minErr --- test/AngularSpec.js | 14 +++---- test/BinderSpec.js | 2 +- test/auto/injectorSpec.js | 30 +++++++------- test/loaderSpec.js | 2 +- test/matchers.js | 5 +-- test/minErrSpec.js | 85 +++++++++++++++++++++++++++++++++++++++ test/ng/animatorSpec.js | 2 +- test/ng/cacheFactorySpec.js | 2 +- test/ng/compileSpec.js | 28 ++++++------- test/ng/controllerSpec.js | 2 +- test/ng/directive/inputSpec.js | 6 +-- test/ng/directive/ngRepeatSpec.js | 8 ++-- test/ng/directive/selectSpec.js | 5 +-- test/ng/interpolateSpec.js | 4 +- test/ng/locationSpec.js | 8 ++-- test/ng/parseSpec.js | 10 ++--- test/ng/rootScopeSpec.js | 12 +++--- test/ngErrorSpec.js | 80 ------------------------------------ 18 files changed, 154 insertions(+), 151 deletions(-) create mode 100644 test/minErrSpec.js delete mode 100644 test/ngErrorSpec.js (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 790f605a..7c004eb1 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -85,20 +85,20 @@ describe('angular', function() { it('should throw an exception if a Scope is being copied', inject(function($rootScope) { expect(function() { copy($rootScope.$new()); }). - toThrow("[NgErr43] Can't copy! Making copies of Window or Scope instances is not supported."); + toThrow("[ng:cpws] Can't copy! Making copies of Window or Scope instances is not supported."); })); it('should throw an exception if a Window is being copied', function() { expect(function() { copy(window); }). - toThrow("[NgErr43] Can't copy! Making copies of Window or Scope instances is not supported."); + toThrow("[ng:cpws] Can't copy! Making copies of Window or Scope instances is not supported."); }); it('should throw an exception when source and destination are equivalent', function() { var src, dst; src = dst = {key: 'value'}; - expect(function() { copy(src, dst); }).toThrow("[NgErr44] Can't copy! Source and destination are identical."); + expect(function() { copy(src, dst); }).toThrow("[ng:cpi] Can't copy! Source and destination are identical."); src = dst = [2, 4]; - expect(function() { copy(src, dst); }).toThrow("[NgErr44] Can't copy! Source and destination are identical."); + expect(function() { copy(src, dst); }).toThrow("[ng:cpi] Can't copy! Source and destination are identical."); }); it('should not copy the private $$hashKey', function() { @@ -582,7 +582,7 @@ describe('angular', function() { expect(function() { angularInit(appElement, bootstrap); - }).toThrow("[NgErr47] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it."); + }).toThrow("[$injector:nomod] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it."); }); }); @@ -726,7 +726,7 @@ describe('angular', function() { expect(function() { angular.bootstrap(element, ['doesntexist']); - }).toThrow("[NgErr47] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it."); + }).toThrow("[$injector:nomod] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it."); expect(element.html()).toBe('{{1+2}}'); dealoc(element); @@ -785,7 +785,7 @@ describe('angular', function() { expect(function() { element.injector().get('foo'); - }).toThrow('[NgErr1] Unknown provider: fooProvider <- foo'); + }).toThrow('[$injector:unpr] Unknown provider: fooProvider <- foo'); expect(element.injector().get('$http')).toBeDefined(); }); diff --git a/test/BinderSpec.js b/test/BinderSpec.js index 2a1b205d..c03b8ace 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -175,7 +175,7 @@ describe('Binder', function() { $rootScope.error['throw'] = function() {throw 'MyError';}; errorLogs.length = 0; $rootScope.$apply(); - expect(errorLogs.shift().message).toBe("[NgErr48] $interpolate error! Can't interpolate: {{error.throw()}}\nMyError"); + expect(errorLogs.shift().message).toBe("[$interpolate:interr] Can't interpolate: {{error.throw()}}\nMyError"); $rootScope.error['throw'] = function() {return 'ok';}; $rootScope.$apply(); diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index b59a344f..4f70fb27 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -70,7 +70,7 @@ describe('injector', function() { it('should provide useful message if no provider', function() { expect(function() { injector.get('idontexist'); - }).toThrow("[NgErr1] Unknown provider: idontexistProvider <- idontexist"); + }).toThrow("[$injector:unpr] Unknown provider: idontexistProvider <- idontexist"); }); @@ -79,7 +79,7 @@ describe('injector', function() { providers('b', function(a) {return 2;}); expect(function() { injector.get('b'); - }).toThrow("[NgErr1] Unknown provider: idontexistProvider <- idontexist <- a <- b"); + }).toThrow("[$injector:unpr] Unknown provider: idontexistProvider <- idontexist <- a <- b"); }); @@ -127,10 +127,10 @@ describe('injector', function() { it('should fail with errors if not function or array', function() { expect(function() { injector.invoke({}); - }).toThrow("[NgErr45] Argument 'fn' is not a function, got Object"); + }).toThrow("[ng:areq] Argument 'fn' is not a function, got Object"); expect(function() { injector.invoke(['a', 123], {}); - }).toThrow("[NgErr45] Argument 'fn' is not a function, got number"); + }).toThrow("[ng:areq] Argument 'fn' is not a function, got number"); }); }); @@ -268,7 +268,7 @@ describe('injector', function() { it('should error on invalid module name', function() { expect(function() { createInjector(['IDontExist'], {}); - }).toThrow("[NgErr47] Module 'IDontExist' is not available! You either misspelled the module name or forgot to load it."); + }).toThrow("[$injector:nomod] Module 'IDontExist' is not available! You either misspelled the module name or forgot to load it."); }); @@ -552,7 +552,7 @@ describe('injector', function() { createInjector([ {} ], {}); - }).toThrow("[NgErr45] Argument 'module' is not a function, got Object"); + }).toThrow("[ng:areq] Argument 'module' is not a function, got Object"); }); @@ -569,7 +569,7 @@ describe('injector', function() { angular.module('TestModule', [], function(xyzzy) {}); expect(function() { createInjector(['TestModule']); - }).toThrow('[NgErr1] Unknown provider: xyzzy from TestModule'); + }).toThrow('[$injector:unpr] Unknown provider: xyzzy from TestModule'); }); @@ -577,7 +577,7 @@ describe('injector', function() { function myModule(xyzzy){} expect(function() { createInjector([myModule]); - }).toThrow('[NgErr1] Unknown provider: xyzzy from ' + myModule); + }).toThrow('[$injector:unpr] Unknown provider: xyzzy from ' + myModule); }); @@ -585,7 +585,7 @@ describe('injector', function() { function myModule(xyzzy){} expect(function() { createInjector([['xyzzy', myModule]]); - }).toThrow('[NgErr1] Unknown provider: xyzzy from ' + myModule); + }).toThrow('[$injector:unpr] Unknown provider: xyzzy from ' + myModule); }); @@ -595,7 +595,7 @@ describe('injector', function() { $provide.factory('service', function(service){}); return function(service) {} }]) - }).toThrow("[NgErr4] Circular dependency found: service"); + }).toThrow("[$injector:cdep] Circular dependency found: service"); }); @@ -606,7 +606,7 @@ describe('injector', function() { $provide.factory('b', function(a){}); return function(a) {} }]) - }).toThrow('[NgErr4] Circular dependency found: b <- a'); + }).toThrow('[$injector:cdep] Circular dependency found: b <- a'); }); }); }); @@ -696,7 +696,7 @@ describe('injector', function() { it('should throw usefull error on wrong argument type]', function() { expect(function() { $injector.invoke({}); - }).toThrow("[NgErr45] Argument 'fn' is not a function, got Object"); + }).toThrow("[ng:areq] Argument 'fn' is not a function, got Object"); }); }); @@ -783,7 +783,7 @@ describe('injector', function() { }]); expect(function() { $injector.get('nameProvider'); - }).toThrow("[NgErr1] Unknown provider: nameProviderProvider <- nameProvider"); + }).toThrow("[$injector:unpr] Unknown provider: nameProviderProvider <- nameProvider"); }); @@ -791,7 +791,7 @@ describe('injector', function() { var $injector = createInjector([]); expect(function() { $injector.get('$provide').value('a', 'b'); - }).toThrow("[NgErr1] Unknown provider: $provideProvider <- $provide"); + }).toThrow("[$injector:unpr] Unknown provider: $provideProvider <- $provide"); }); @@ -801,7 +801,7 @@ describe('injector', function() { createInjector([function($provide) { $provide.value('name', 'angular') }, instanceLookupInModule]); - }).toThrow('[NgErr1] Unknown provider: name from ' + String(instanceLookupInModule)); + }).toThrow('[$injector:unpr] Unknown provider: name from ' + String(instanceLookupInModule)); }); }); }); diff --git a/test/loaderSpec.js b/test/loaderSpec.js index 802d5c1d..ce98c50a 100644 --- a/test/loaderSpec.js +++ b/test/loaderSpec.js @@ -68,6 +68,6 @@ describe('module loader', function() { it('should complain of no module', function() { expect(function() { window.angular.module('dontExist'); - }).toThrow("[NgErr47] Module 'dontExist' is not available! You either misspelled the module name or forgot to load it."); + }).toThrow("[$injector:nomod] Module 'dontExist' is not available! You either misspelled the module name or forgot to load it."); }); }); diff --git a/test/matchers.js b/test/matchers.js index 44d6b61e..67efd3e7 100644 --- a/test/matchers.js +++ b/test/matchers.js @@ -149,9 +149,8 @@ beforeEach(function() { angular.element(this.actual).hasClass(clazz); }, - toThrowNg: function(expected) { - return jasmine.Matchers.prototype.toThrow.call(this, new RegExp('\\[NgErr\\d*\\] ' + - expected.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"))); + toThrowMatching: function(expected) { + return jasmine.Matchers.prototype.toThrow.call(this, expected); } }); }); diff --git a/test/minErrSpec.js b/test/minErrSpec.js new file mode 100644 index 00000000..4ee569e0 --- /dev/null +++ b/test/minErrSpec.js @@ -0,0 +1,85 @@ +'use strict'; + +describe('minErr', function () { + + var supportStackTraces = function() { + var e = new Error(); + return isDefined(e.stack); + }; + var emptyTestError = minErr(), + testError = minErr('test'); + + it('should return an Error factory', function() { + var myError = testError('test', 'Oops'); + expect(myError instanceof Error).toBe(true); + }); + + it('should generate stack trace at the frame where the minErr instance was called', function() { + var myError; + + function someFn() { + function nestedFn() { + myError = testError('fail', "I fail!"); + } + nestedFn(); + } + + someFn(); + + // only Chrome, Firefox have stack + if (!supportStackTraces()) return; + + expect(myError.stack).toMatch(/^[.\s\S]+nestedFn[.\s\S]+someFn.+/); + }); + + it('should interpolate string arguments without quotes', function() { + var myError = testError('1', 'This {0} is "{1}"', 'foo', 'bar'); + expect(myError.message).toBe('[test:1] This foo is "bar"'); + }); + + it('should interpolate non-string arguments', function() { + var arr = [1, 2, 3], + obj = {a: 123, b: 'baar'}, + anonFn = function(something) { return something; }, + namedFn = function foo(something) { return something; }, + myError; + + myError = testError('26', 'arr: {0}; obj: {1}; anonFn: {2}; namedFn: {3}', + arr, obj, anonFn, namedFn); + + expect(myError.message).toContain('[test:26] arr: [1,2,3]; obj: {"a":123,"b":"baar"};'); + // IE does not add space after "function" + expect(myError.message).toMatch(/anonFn: function\s?\(something\);/); + expect(myError.message).toContain('namedFn: function foo(something)'); + }); + + it('should not suppress falsy objects', function() { + var myError = testError('26', 'false: {0}; zero: {1}; null: {2}; undefined: {3}; emptyStr: {4}', + false, 0, null, undefined, ''); + expect(myError.message). + toBe('[test:26] false: false; zero: 0; null: null; undefined: undefined; emptyStr: '); + }); + + + it('should preserve interpolation markers when fewer arguments than needed are provided', function() { + // this way we can easily see if we are passing fewer args than needed + + var foo = 'Fooooo', + myError = testError('26', 'This {0} is {1} on {2}', foo); + + expect(myError.message).toBe('[test:26] This Fooooo is {1} on {2}'); + }); + + + it('should pass through the message if no interpolation is needed', function() { + var myError = testError('26', 'Something horrible happened!'); + expect(myError.message).toBe('[test:26] Something horrible happened!'); + }); + + it('should include a namespace in the message only if it is namespaced', function () { + var myError = emptyTestError('26', 'This is a {0}', 'Foo'); + var myNamespacedError = testError('26', 'That is a {0}', 'Bar'); + expect(myError.message).toBe('[26] This is a Foo'); + expect(myNamespacedError.message).toBe('[test:26] That is a Bar'); + }); +}); diff --git a/test/ng/animatorSpec.js b/test/ng/animatorSpec.js index 63fcf5c3..8fb9f05f 100644 --- a/test/ng/animatorSpec.js +++ b/test/ng/animatorSpec.js @@ -768,6 +768,6 @@ describe("$animator", function() { expect(function() { var animate = $animator($rootScope, { ngAnimate: ':' }); animate.enter(); - }).toThrow("[NgErr24] Syntax Error: Token ':' not a primary expression at column 1 of the expression [:] starting at [:]."); + }).toThrow("[$parse:syntax] Syntax Error: Token ':' not a primary expression at column 1 of the expression [:] starting at [:]."); })); }); diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index 4b15fd7b..c398a55e 100644 --- a/test/ng/cacheFactorySpec.js +++ b/test/ng/cacheFactorySpec.js @@ -15,7 +15,7 @@ describe('$cacheFactory', function() { it('should complain if the cache id is being reused', inject(function($cacheFactory) { $cacheFactory('cache1'); expect(function() { $cacheFactory('cache1'); }). - toThrow("[NgErr10] CacheId 'cache1' is already taken!"); + toThrow("[$cacheFactory:iid] CacheId 'cache1' is already taken!"); })); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 99c0a6ad..8b48ea08 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -632,11 +632,11 @@ describe('$compile', function() { inject(function($compile) { expect(function() { $compile('

'); - }).toThrow("[NgErr12] Template for directive 'noRootElem' must have exactly one root element."); + }).toThrow("[$compile:tplrt] Template for directive 'noRootElem' must have exactly one root element. "); expect(function() { $compile('

'); - }).toThrow("[NgErr12] Template for directive 'multiRootElem' must have exactly one root element."); + }).toThrow("[$compile:tplrt] Template for directive 'multiRootElem' must have exactly one root element. "); // ws is ok expect(function() { @@ -985,7 +985,7 @@ describe('$compile', function() { expect(function() { $httpBackend.flush(); - }).toThrow('[NgErr17] Failed to load template: hello.html'); + }).toThrow('[$compile:tpload] Failed to load template: hello.html'); expect(sortedHtml(element)).toBe('
'); } )); @@ -1005,7 +1005,7 @@ describe('$compile', function() { inject(function($compile){ expect(function() { $compile('
'); - }).toThrow('[NgErr18] Multiple directives [sync, async] asking for template on: '+ + }).toThrow('[$compile:multidir] Multiple directives [sync, async] asking for template on: '+ '
'); }); }); @@ -1189,14 +1189,14 @@ describe('$compile', function() { $compile('

'); $rootScope.$digest(); expect($exceptionHandler.errors.pop().message). - toBe("[NgErr16] Template for directive 'template' must have exactly one root element. Template: template.html"); + toBe("[$compile:tplrt] Template for directive 'template' must have exactly one root element. template.html"); // multi root $templateCache.put('template.html', '
'); $compile('

'); $rootScope.$digest(); expect($exceptionHandler.errors.pop().message). - toBe("[NgErr16] Template for directive 'template' must have exactly one root element. Template: template.html"); + toBe("[$compile:tplrt] Template for directive 'template' must have exactly one root element. template.html"); // ws is ok $templateCache.put('template.html', '
\n'); @@ -1456,7 +1456,7 @@ describe('$compile', function() { function($rootScope, $compile) { expect(function(){ $compile('
'); - }).toThrow('[NgErr18] Multiple directives [iscopeA, scopeB] asking for isolated scope on: ' + + }).toThrow('[$compile:multidir] Multiple directives [iscopeA, scopeB] asking for isolated scope on: ' + '
'); }) ); @@ -1466,7 +1466,7 @@ describe('$compile', function() { function($rootScope, $compile) { expect(function(){ $compile('
'); - }).toThrow('[NgErr18] Multiple directives [iscopeA, iscopeB] asking for isolated scope on: ' + + }).toThrow('[$compile:multidir] Multiple directives [iscopeA, iscopeB] asking for isolated scope on: ' + '
'); }) ); @@ -2074,7 +2074,7 @@ describe('$compile', function() { componentScope.ref = 'ignore me'; expect($rootScope.$apply). - toThrow("[NgErr14] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!"); + toThrow("[$compile:noass] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!"); expect(componentScope.ref).toBe('hello world'); // reset since the exception was rethrown which prevented phase clearing $rootScope.$$phase = null; @@ -2150,7 +2150,7 @@ describe('$compile', function() { it('should throw on unknown definition', inject(function() { expect(function() { compile('
'); - }).toThrow("[NgErr15] Invalid isolate scope definition for directive 'badDeclaration'. Definition: {... attr: 'xxx' ...}"); + }).toThrow("[$compile:iscp] Invalid isolate scope definition for directive 'badDeclaration'. Definition: {... attr: 'xxx' ...}"); })); it('should expose a $$isolateBindings property onto the scope', inject(function() { @@ -2247,7 +2247,7 @@ describe('$compile', function() { inject(function(log, $compile, $rootScope) { expect(function() { $compile('
')($rootScope); - }).toThrow("[NgErr13] Controller 'main', required by directive 'dep', can't be found!"); + }).toThrow("[$compile:ctreq] Controller 'main', required by directive 'dep', can't be found!"); }); }); @@ -2434,7 +2434,7 @@ describe('$compile', function() { inject(function($compile) { expect(function() { $compile('
'); - }).toThrow('[NgErr18] Multiple directives [first, second] asking for transclusion on: ' + + }).toThrow('[$compile:multidir] Multiple directives [first, second] asking for transclusion on: ' + '
'); }); }); @@ -2816,7 +2816,7 @@ describe('$compile', function() { '
' + '' + '
'); - }).toThrow("[NgErr51] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); + }).toThrow("[$compile:utrat] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); }); }); @@ -2834,7 +2834,7 @@ describe('$compile', function() { '
' + '' + '
'); - }).toThrow("[NgErr51] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); + }).toThrow("[$compile:utrat] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); }); }); diff --git a/test/ng/controllerSpec.js b/test/ng/controllerSpec.js index b041dec7..6446ecf9 100644 --- a/test/ng/controllerSpec.js +++ b/test/ng/controllerSpec.js @@ -131,7 +131,7 @@ describe('$controller', function() { expect(function() { $controller('a.b.FooCtrl as foo'); - }).toThrow("[NgErr47] Cannot export controller 'a.b.FooCtrl' as 'foo'! No $scope object provided via `locals`."); + }).toThrow("[$controller:noscp] Cannot export controller 'a.b.FooCtrl' as 'foo'! No $scope object provided via `locals`."); }); }); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 68caf1f5..5e1b26af 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -43,7 +43,7 @@ describe('NgModelController', function() { } expect(exception.message). - toMatch(/^\[NgErr6\] ngModel error! Expression '1\+2' is non\-assignable\. Element: $/); + toMatch(/^\[ngModel:noass\] Expression '1\+2' is non\-assignable\. Element: $/); })); @@ -457,7 +457,7 @@ describe('input', function() { expect(function() { compileInput(''); scope.$digest(); - }).toThrow("[NgErr24] Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); + }).toThrow("[$parse:syntax] Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); }); @@ -552,7 +552,7 @@ describe('input', function() { expect(function() { compileInput(''); scope.$apply(); - }).toThrowNg('ngPattern error! Expected fooRegexp to be a RegExp but was undefined.'); + }).toThrowMatching(/^\[ngPattern:noregexp\] Expected fooRegexp to be a RegExp but was/); }); }); diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 2a0d5284..9fc445ba 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -269,7 +269,7 @@ describe('ngRepeat', function() { element = jqLite('
'); $compile(element)(scope); expect($exceptionHandler.errors.shift()[0].message). - toBe("[NgErr7] ngRepeat error! Expected expression in form of '_item_ in _collection_[ track by _id_]' but got 'i dont parse'."); + toBe("[ngRepeat:iexp] Expected expression in form of '_item_ in _collection_[ track by _id_]' but got 'i dont parse'."); }); @@ -277,7 +277,7 @@ describe('ngRepeat', function() { element = jqLite('
'); $compile(element)(scope); expect($exceptionHandler.errors.shift()[0].message). - toBe("[NgErr8] ngRepeat error! '_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got 'i dont parse'."); + toBe("[ngRepeat:iidexp] '_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got 'i dont parse'."); }); @@ -481,7 +481,7 @@ describe('ngRepeat', function() { scope.items = [a, a, a]; scope.$digest(); expect($exceptionHandler.errors.shift().message). - toEqual("[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: object:003"); + toEqual("[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: object:003"); // recover scope.items = [a]; @@ -501,7 +501,7 @@ describe('ngRepeat', function() { scope.items = [d, d, d]; scope.$digest(); expect($exceptionHandler.errors.shift().message). - toEqual("[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: object:009"); + toEqual("[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: object:009"); // recover scope.items = [a]; diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 5a168f53..5be7eb65 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -493,9 +493,8 @@ describe('select', function() { it('should throw when not formated "? for ? in ?"', function() { expect(function() { - compile(''); - }).toThrowNg("ngOptions error! Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in" + - " _collection_' but got 'i dont parse'."); + compile(''); + }).toThrowMatching(/^\[ngOptions:iexp\] Expected expression in form of/); }); diff --git a/test/ng/interpolateSpec.js b/test/ng/interpolateSpec.js index 0af38506..454d81aa 100644 --- a/test/ng/interpolateSpec.js +++ b/test/ng/interpolateSpec.js @@ -32,7 +32,7 @@ describe('$interpolate', function() { }; expect(function () { $interpolate('{{err()}}')($rootScope); - }).toThrow("[NgErr48] $interpolate error! Can't interpolate: {{err()}}\nError: oops"); + }).toThrow("[$interpolate:interr] Can't interpolate: {{err()}}\nError: oops"); })); it('should stop interpolation when encountering an exception', inject(function($interpolate, $compile, $rootScope) { @@ -43,7 +43,7 @@ describe('$interpolate', function() { $compile(dom)($rootScope); expect(function () { $rootScope.$apply(); - }).toThrow("[NgErr48] $interpolate error! Can't interpolate: {{err()}}\nError: oops"); + }).toThrow("[$interpolate:interr] Can't interpolate: {{err()}}\nError: oops"); expect(dom[0].innerHTML).toEqual('2'); expect(dom[1].innerHTML).toEqual('{{err()}}'); expect(dom[2].innerHTML).toEqual('{{1 + 2}}'); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index ee920ed9..9e4b3bd6 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -190,7 +190,7 @@ describe('$location', function() { expect(function() { url.$$parse('http://other.server.org/path#/path'); - }).toThrow('[NgErr21] $location error! Invalid url "http://other.server.org/path#/path", missing path prefix "http://server.org/base/".'); + }).toThrow('[$location:nopp] Invalid url "http://other.server.org/path#/path", missing path prefix "http://server.org/base/".'); }); @@ -199,7 +199,7 @@ describe('$location', function() { expect(function() { url.$$parse('http://server.org/path#/path'); - }).toThrow('[NgErr21] $location error! Invalid url "http://server.org/path#/path", missing path prefix "http://server.org/base/".'); + }).toThrow('[$location:nopp] Invalid url "http://server.org/path#/path", missing path prefix "http://server.org/base/".'); }); @@ -312,14 +312,14 @@ describe('$location', function() { it('should throw error when invalid server url given', function() { expect(function() { url.$$parse('http://server.org/path#/path'); - }).toThrow('[NgErr22] $location error! Invalid url "http://server.org/path#/path", does not start with "http://www.server.org:1234/base".'); + }).toThrow('[$location:istart] Invalid url "http://server.org/path#/path", does not start with "http://www.server.org:1234/base".'); }); it('should throw error when invalid hashbang prefix given', function() { expect(function() { url.$$parse('http://www.server.org:1234/base#/path'); - }).toThrow('[NgErr49] $location error! Invalid url "http://www.server.org:1234/base#/path", missing hash prefix "#!".'); + }).toThrow('[$location:nohash] Invalid url "http://www.server.org:1234/base#/path", missing hash prefix "#!".'); }); diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index c3cb0ce1..f73a6021 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -156,11 +156,11 @@ describe('parser', function() { it('should throws exception for invalid exponent', function() { expect(function() { lex("0.5E-"); - }).toThrow(new Error('[NgErr23] Lexer Error: Invalid exponent at column 4 in expression [0.5E-].')); + }).toThrow(new Error('[$parse:lexerr] Lexer Error: Invalid exponent at column 4 in expression [0.5E-].')); expect(function() { lex("0.5E-A"); - }).toThrow(new Error('[NgErr23] Lexer Error: Invalid exponent at column 4 in expression [0.5E-A].')); + }).toThrow(new Error('[$parse:lexerr] Lexer Error: Invalid exponent at column 4 in expression [0.5E-A].')); }); it('should tokenize number starting with a dot', function() { @@ -171,7 +171,7 @@ describe('parser', function() { it('should throw error on invalid unicode', function() { expect(function() { lex("'\\u1''bla'"); - }).toThrow(new Error("[NgErr23] Lexer Error: Invalid unicode escape [\\u1''b] at column 2 in expression ['\\u1''bla'].")); + }).toThrow(new Error("[$parse:lexerr] Lexer Error: Invalid unicode escape [\\u1''b] at column 2 in expression ['\\u1''bla'].")); }); }); @@ -304,7 +304,7 @@ describe('parser', function() { expect(function() { scope.$eval("1|nonexistent"); - }).toThrow(new Error("[NgErr1] Unknown provider: nonexistentFilterProvider <- nonexistentFilter")); + }).toThrow(new Error("[$injector:unpr] Unknown provider: nonexistentFilterProvider <- nonexistentFilter")); scope.offset = 3; expect(scope.$eval("'abcd'|substring:1:offset")).toEqual("bc"); @@ -492,7 +492,7 @@ describe('parser', function() { it('should throw exception on non-closed bracket', function() { expect(function() { scope.$eval('[].count('); - }).toThrow('[NgErr25] Unexpected end of expression: [].count('); + }).toThrow('[$parse:ueoe] Unexpected end of expression: [].count('); }); it('should evaluate double negation', function() { diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 0b258c83..9d86c098 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -215,7 +215,7 @@ describe('Scope', function() { expect(function() { $rootScope.$digest(); - }).toThrow('[NgErr27] 100 $digest() iterations reached. Aborting!\n'+ + }).toThrow('[$rootScope:infdig] 100 $digest() iterations reached. Aborting!\n'+ 'Watchers fired in the last 5 iterations: ' + '[["a; newVal: 96; oldVal: 95","b; newVal: 97; oldVal: 96"],' + '["a; newVal: 97; oldVal: 96","b; newVal: 98; oldVal: 97"],' + @@ -299,7 +299,7 @@ describe('Scope', function() { $rootScope.$watch('name', function() { expect(function() { $rootScope.$digest(); - }).toThrow('[NgErr28] $digest already in progress'); + }).toThrow('[$rootScope:inprog] $digest already in progress'); callCount++; }); $rootScope.name = 'a'; @@ -759,7 +759,7 @@ describe('Scope', function() { $rootScope.$apply(function() { $rootScope.$apply(); }); - }).toThrow('[NgErr28] $apply already in progress'); + }).toThrow('[$rootScope:inprog] $apply already in progress'); })); @@ -771,7 +771,7 @@ describe('Scope', function() { $rootScope.$apply(); }); }); - }).toThrow('[NgErr28] $digest already in progress'); + }).toThrow('[$rootScope:inprog] $digest already in progress'); })); @@ -781,7 +781,7 @@ describe('Scope', function() { childScope1.$watch('x', function() { childScope1.$apply(); }); - expect(function() { childScope1.$apply(); }).toThrow('[NgErr28] $digest already in progress'); + expect(function() { childScope1.$apply(); }).toThrow('[$rootScope:inprog] $digest already in progress'); })); @@ -798,7 +798,7 @@ describe('Scope', function() { expect(function() { childScope2.$apply(function() { childScope2.x = 'something'; - }); }).toThrow('[NgErr28] $digest already in progress'); + }); }).toThrow('[$rootScope:inprog] $digest already in progress'); })); }); }); diff --git a/test/ngErrorSpec.js b/test/ngErrorSpec.js deleted file mode 100644 index 81773322..00000000 --- a/test/ngErrorSpec.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -describe('ngError', function() { - - var supportStackTraces = function() { - var e = new Error(); - return isDefined(e.stack); - }; - - it('should return an Error instance', function() { - var myError = ngError(); - expect(myError instanceof Error).toBe(true); - }); - - - it('should generate stack trace at the frame where ngError was called', function() { - var myError; - - function someFn() { - function nestedFn() { - myError = ngError(0, "I fail!"); - } - nestedFn(); - } - - someFn(); - - // only Chrome, Firefox have stack - if (!supportStackTraces()) return; - - expect(myError.stack).toMatch(/^[.\s\S]+nestedFn[.\s\S]+someFn.+/); - }); - - - it('should interpolate string arguments without quotes', function() { - var myError = ngError(26, 'This {0} is "{1}"', 'foo', 'bar'); - expect(myError.message).toBe('[NgErr26] This foo is "bar"'); - }); - - - it('should interpolate non-string arguments', function() { - var arr = [1, 2, 3], - obj = {a: 123, b: 'baar'}, - anonFn = function(something) { return something; }, - namedFn = function foo(something) { return something; }, - myError; - - myError = ngError(26, 'arr: {0}; obj: {1}; anonFn: {2}; namedFn: {3}', - arr, obj, anonFn, namedFn); - - expect(myError.message).toContain('[NgErr26] arr: [1,2,3]; obj: {"a":123,"b":"baar"};'); - // IE does not add space after "function" - expect(myError.message).toMatch(/anonFn: function\s?\(something\);/); - expect(myError.message).toContain('namedFn: function foo(something)'); - }); - - - it('should not suppress falsy objects', function() { - var myError = ngError(26, 'false: {0}; zero: {1}; null: {2}; undefined: {3}; emptyStr: {4}', - false, 0, null, undefined, ''); - expect(myError.message). - toBe('[NgErr26] false: false; zero: 0; null: null; undefined: undefined; emptyStr: '); - }); - - - it('should preserve interpolation markers when fewer arguments than needed are provided', function() { - // this way we can easily see if we are passing fewer args than needed - - var foo = 'Fooooo', - myError = ngError(26, 'This {0} is {1} on {2}', foo); - - expect(myError.message).toBe('[NgErr26] This Fooooo is {1} on {2}'); - }); - - - it('should pass through the message if no interpolation is needed', function() { - var myError = ngError(26, 'Something horrible happened!'); - expect(myError.message).toBe('[NgErr26] Something horrible happened!'); - }); -}); -- cgit v1.2.3