diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 10 | ||||
| -rw-r--r-- | test/BinderSpec.js | 2 | ||||
| -rw-r--r-- | test/auto/injectorSpec.js | 39 | ||||
| -rw-r--r-- | test/jqLiteSpec.js | 6 | ||||
| -rw-r--r-- | test/loaderSpec.js | 2 | ||||
| -rw-r--r-- | test/matchers.js | 47 | ||||
| -rw-r--r-- | test/minErrSpec.js | 16 | ||||
| -rw-r--r-- | test/ng/animateSpec.js | 2 | ||||
| -rw-r--r-- | test/ng/cacheFactorySpec.js | 2 | ||||
| -rwxr-xr-x | test/ng/compileSpec.js | 54 | ||||
| -rw-r--r-- | test/ng/controllerSpec.js | 2 | ||||
| -rw-r--r-- | test/ng/directive/booleanAttrsSpec.js | 10 | ||||
| -rw-r--r-- | test/ng/directive/inputSpec.js | 4 | ||||
| -rw-r--r-- | test/ng/directive/ngRepeatSpec.js | 10 | ||||
| -rw-r--r-- | test/ng/directive/ngSrcSpec.js | 12 | ||||
| -rw-r--r-- | test/ng/directive/selectSpec.js | 2 | ||||
| -rw-r--r-- | test/ng/interpolateSpec.js | 16 | ||||
| -rw-r--r-- | test/ng/locationSpec.js | 10 | ||||
| -rw-r--r-- | test/ng/parseSpec.js | 116 | ||||
| -rw-r--r-- | test/ng/rootScopeSpec.js | 12 | ||||
| -rw-r--r-- | test/ng/sceSpecs.js | 76 | ||||
| -rw-r--r-- | test/ngResource/resourceSpec.js | 28 | ||||
| -rw-r--r-- | test/ngRoute/routeSpec.js | 3 |
23 files changed, 266 insertions, 215 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index f049c2fd..415ff25d 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -108,20 +108,20 @@ describe('angular', function() { it('should throw an exception if a Scope is being copied', inject(function($rootScope) { expect(function() { copy($rootScope.$new()); }). - toThrow("[ng:cpws] Can't copy! Making copies of Window or Scope instances is not supported."); + toThrowMinErr("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("[ng:cpws] Can't copy! Making copies of Window or Scope instances is not supported."); + toThrowMinErr("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("[ng:cpi] Can't copy! Source and destination are identical."); + expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical."); src = dst = [2, 4]; - expect(function() { copy(src, dst); }).toThrow("[ng:cpi] Can't copy! Source and destination are identical."); + expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical."); }); it('should not copy the private $$hashKey', function() { @@ -901,7 +901,7 @@ describe('angular', function() { expect(function() { element.injector().get('foo'); - }).toThrow('[$injector:unpr] Unknown provider: fooProvider <- foo'); + }).toThrowMinErr('$injector', 'unpr', 'Unknown provider: fooProvider <- foo'); expect(element.injector().get('$http')).toBeDefined(); }); diff --git a/test/BinderSpec.js b/test/BinderSpec.js index c03b8ace..3c204b64 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("[$interpolate:interr] Can't interpolate: {{error.throw()}}\nMyError"); + expect(errorLogs.shift().message).toMatch(/^\[\$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 2c485655..efed2aa4 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("[$injector:unpr] Unknown provider: idontexistProvider <- idontexist"); + }).toThrowMinErr("$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("[$injector:unpr] Unknown provider: idontexistProvider <- idontexist <- a <- b"); + }).toThrowMinErr("$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("[ng:areq] Argument 'fn' is not a function, got Object"); + }).toThrowMinErr("ng", "areq", "Argument 'fn' is not a function, got Object"); expect(function() { injector.invoke(['a', 123], {}); - }).toThrow("[ng:areq] Argument 'fn' is not a function, got number"); + }).toThrowMinErr("ng", "areq", "Argument 'fn' is not a function, got number"); }); }); @@ -268,9 +268,8 @@ describe('injector', function() { it('should error on invalid module name', function() { expect(function() { createInjector(['IDontExist'], {}); - }).toThrowMatching( - /\[\$injector:modulerr\].+\n.*\[\$injector:nomod] Module 'IDontExist' is not available! You either misspelled the module name or forgot to load it/ - ); + }).toThrowMinErr('$injector', 'modulerr', + /\[\$injector:nomod\] Module 'IDontExist' is not available! You either misspelled the module name or forgot to load it/); }); @@ -553,7 +552,7 @@ describe('injector', function() { createInjector([ {} ], {}); - }).toThrowMatching(/\[\$injector:modulerr\] Failed to instantiate module {} due to:\n.*\[ng\:areq] Argument 'module' is not a function, got Object/); + }).toThrowMinErr('$injector', 'modulerr', /Failed to instantiate module \{\} due to:\n.*\[ng:areq\] Argument 'module' is not a function, got Object/); }); @@ -562,7 +561,7 @@ describe('injector', function() { createInjector([function() { throw 'MyError'; }], {}); - }).toThrowMatching(/\[\$injector:modulerr\] Failed to instantiate module .+ due to:\n.*MyError/); + }).toThrowMinErr('$injector', 'modulerr', /Failed to instantiate module .+ due to:\n.*MyError/); }); @@ -570,8 +569,8 @@ describe('injector', function() { angular.module('TestModule', [], function(xyzzy) {}); expect(function() { createInjector(['TestModule' ]); - }).toThrowMatching( - /\[\$injector:modulerr\] Failed to instantiate module TestModule due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/ + }).toThrowMinErr( + '$injector', 'modulerr', /Failed to instantiate module TestModule due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/ ); }); @@ -580,8 +579,8 @@ describe('injector', function() { function myModule(xyzzy){} expect(function() { createInjector([myModule]); - }).toThrowMatching( - /\[\$injector:modulerr\] Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/ + }).toThrowMinErr( + '$injector', 'modulerr', /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/ ); }); @@ -590,8 +589,8 @@ describe('injector', function() { function myModule(xyzzy){} expect(function() { createInjector([['xyzzy', myModule]]); - }).toThrowMatching( - /\[\$injector:modulerr\] Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/ + }).toThrowMinErr( + '$injector', 'modulerr', /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/ ); }); @@ -602,7 +601,7 @@ describe('injector', function() { $provide.factory('service', function(service){}); return function(service) {} }]) - }).toThrow("[$injector:cdep] Circular dependency found: service"); + }).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service'); }); @@ -613,7 +612,7 @@ describe('injector', function() { $provide.factory('b', function(a){}); return function(a) {} }]) - }).toThrow('[$injector:cdep] Circular dependency found: b <- a'); + }).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: b <- a'); }); }); }); @@ -703,7 +702,7 @@ describe('injector', function() { it('should throw usefull error on wrong argument type]', function() { expect(function() { $injector.invoke({}); - }).toThrow("[ng:areq] Argument 'fn' is not a function, got Object"); + }).toThrowMinErr("ng", "areq", "Argument 'fn' is not a function, got Object"); }); }); @@ -790,7 +789,7 @@ describe('injector', function() { }]); expect(function() { $injector.get('nameProvider'); - }).toThrow("[$injector:unpr] Unknown provider: nameProviderProvider <- nameProvider"); + }).toThrowMinErr("$injector", "unpr", "Unknown provider: nameProviderProvider <- nameProvider"); }); @@ -798,7 +797,7 @@ describe('injector', function() { var $injector = createInjector([]); expect(function() { $injector.get('$provide').value('a', 'b'); - }).toThrow("[$injector:unpr] Unknown provider: $provideProvider <- $provide"); + }).toThrowMinErr("$injector", "unpr", "Unknown provider: $provideProvider <- $provide"); }); diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 913e6192..79c0d0c6 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -900,15 +900,15 @@ describe('jqLite', function() { expect(function() { elm.on('click', anObj, callback); - }).toThrowMatching(/\[jqLite\:onargs\]/); + }).toThrowMinErr('jqLite', 'onargs'); expect(function() { elm.on('click', null, aString, callback); - }).toThrowMatching(/\[jqLite\:onargs\]/); + }).toThrowMinErr('jqLite', 'onargs'); expect(function() { elm.on('click', aValue, callback); - }).toThrowMatching(/\[jqLite\:onargs\]/); + }).toThrowMinErr('jqLite', 'onargs'); }); } diff --git a/test/loaderSpec.js b/test/loaderSpec.js index 73e94215..302852cb 100644 --- a/test/loaderSpec.js +++ b/test/loaderSpec.js @@ -68,7 +68,7 @@ describe('module loader', function() { it('should complain of no module', function() { expect(function() { window.angular.module('dontExist'); - }).toThrow("[$injector:nomod] Module 'dontExist' is not available! You either misspelled the module name " + + }).toThrowMinErr("$injector", "nomod", "Module 'dontExist' is not available! You either misspelled the module name " + "or forgot to load it. If registering a module ensure that you specify the dependencies as the second " + "argument."); }); diff --git a/test/matchers.js b/test/matchers.js index b7d336b7..57bf35c7 100644 --- a/test/matchers.js +++ b/test/matchers.js @@ -165,6 +165,53 @@ beforeEach(function() { toThrowMatching: function(expected) { return jasmine.Matchers.prototype.toThrow.call(this, expected); + }, + + toThrowMinErr: function(namespace, code, content) { + var result, + exception, + exceptionMessage = '', + escapeRegexp = function (str) { + // This function escapes all special regex characters. + // We use it to create matching regex from arbitrary strings. + // http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + codeRegex = new RegExp('^\\[' + escapeRegexp(namespace) + ':' + escapeRegexp(code) + '\\]'), + not = this.isNot ? "not " : "", + regex = jasmine.isA_("RegExp", content) ? content : + isDefined(content) ? new RegExp(escapeRegexp(content)) : undefined; + + if(!isFunction(this.actual)) { + throw new Error('Actual is not a function'); + } + + try { + this.actual(); + } catch (e) { + exception = e; + } + + if (exception) { + exceptionMessage = exception.message || exception; + } + + this.message = function () { + return "Expected function " + not + "to throw " + + namespace + "MinErr('" + code + "')" + + (regex ? " matching " + regex.toString() : "") + + (exception ? ", but it threw " + exceptionMessage : "."); + }; + + result = codeRegex.test(exceptionMessage); + if (!result) { + return result; + } + + if (isDefined(regex)) { + return regex.test(exceptionMessage); + } + return result; } }); }); diff --git a/test/minErrSpec.js b/test/minErrSpec.js index 4ee569e0..6b7d93b8 100644 --- a/test/minErrSpec.js +++ b/test/minErrSpec.js @@ -1,12 +1,12 @@ 'use strict'; describe('minErr', function () { - + var supportStackTraces = function() { var e = new Error(); return isDefined(e.stack); }; - var emptyTestError = minErr(), + var emptyTestError = minErr(), testError = minErr('test'); it('should return an Error factory', function() { @@ -34,7 +34,7 @@ describe('minErr', function () { 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"'); + expect(myError.message).toMatch(/^\[test:1\] This foo is "bar"/); }); it('should interpolate non-string arguments', function() { @@ -57,7 +57,7 @@ describe('minErr', 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: '); + toMatch(/^\[test:26\] false: false; zero: 0; null: null; undefined: undefined; emptyStr: /); }); @@ -67,19 +67,19 @@ describe('minErr', function () { 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}'); + expect(myError.message).toMatch(/^\[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!'); + expect(myError.message).toMatch(/^\[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'); + expect(myError.message).toMatch(/^\[26\] This is a Foo/); + expect(myNamespacedError.message).toMatch(/^\[test:26\] That is a Bar/); }); }); diff --git a/test/ng/animateSpec.js b/test/ng/animateSpec.js index 2e9034e4..79115c1e 100644 --- a/test/ng/animateSpec.js +++ b/test/ng/animateSpec.js @@ -44,7 +44,7 @@ describe("$animate", function() { module(function($animateProvider) { expect(function() { $animateProvider.register('abc', null); - }).toThrow("[$animate:notcsel] Expecting class selector starting with '.' got 'abc'."); + }).toThrowMinErr("$animate", "notcsel", "Expecting class selector starting with '.' got 'abc'."); }); inject(); }); diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index c398a55e..b1a018da 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("[$cacheFactory:iid] CacheId 'cache1' is already taken!"); + toThrowMinErr("$cacheFactory", "iid", "CacheId 'cache1' is already taken!"); })); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index ba94c48b..28dc57fe 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -632,11 +632,11 @@ describe('$compile', function() { inject(function($compile) { expect(function() { $compile('<p no-root-elem></p>'); - }).toThrow("[$compile:tplrt] Template for directive 'noRootElem' must have exactly one root element. "); + }).toThrowMinErr("$compile", "tplrt", "Template for directive 'noRootElem' must have exactly one root element. "); expect(function() { $compile('<p multi-root-elem></p>'); - }).toThrow("[$compile:tplrt] Template for directive 'multiRootElem' must have exactly one root element. "); + }).toThrowMinErr("$compile", "tplrt", "Template for directive 'multiRootElem' must have exactly one root element. "); // ws is ok expect(function() { @@ -748,7 +748,7 @@ describe('$compile', function() { expect(function() { $templateCache.put('http://example.com/should-not-load.html', 'Should not load even if in cache.'); $compile('<div class="crossDomainTemplate"></div>')($rootScope); - }).toThrow('[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/should-not-load.html'); + }).toThrowMinErr('$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/should-not-load.html'); })); it('should load cross domain templates when trusted', inject( @@ -1011,7 +1011,7 @@ describe('$compile', function() { expect(function() { $httpBackend.flush(); - }).toThrow('[$compile:tpload] Failed to load template: hello.html'); + }).toThrowMinErr('$compile', 'tpload', 'Failed to load template: hello.html'); expect(sortedHtml(element)).toBe('<div><b class="hello"></b></div>'); } )); @@ -1031,7 +1031,7 @@ describe('$compile', function() { inject(function($compile){ expect(function() { $compile('<div><div class="sync async"></div></div>'); - }).toThrow('[$compile:multidir] Multiple directives [sync, async] asking for template on: '+ + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [sync, async] asking for template on: '+ '<div class="sync async">'); }); }); @@ -1215,14 +1215,14 @@ describe('$compile', function() { $compile('<p template></p>'); $rootScope.$digest(); expect($exceptionHandler.errors.pop().message). - toBe("[$compile:tplrt] Template for directive 'template' must have exactly one root element. template.html"); + toMatch(/\[\$compile:tplrt\] Template for directive 'template' must have exactly one root element\. template\.html/); // multi root $templateCache.put('template.html', '<div></div><div></div>'); $compile('<p template></p>'); $rootScope.$digest(); expect($exceptionHandler.errors.pop().message). - toBe("[$compile:tplrt] Template for directive 'template' must have exactly one root element. template.html"); + toMatch(/\[\$compile:tplrt\] Template for directive 'template' must have exactly one root element\. template\.html/); // ws is ok $templateCache.put('template.html', ' <div></div> \n'); @@ -1482,7 +1482,7 @@ describe('$compile', function() { function($rootScope, $compile) { expect(function(){ $compile('<div class="iscope-a; scope-b"></div>'); - }).toThrow('[$compile:multidir] Multiple directives [iscopeA, scopeB] asking for isolated scope on: ' + + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [iscopeA, scopeB] asking for isolated scope on: ' + '<div class="iscope-a; scope-b ng-isolate-scope ng-scope">'); }) ); @@ -1492,7 +1492,7 @@ describe('$compile', function() { function($rootScope, $compile) { expect(function(){ $compile('<div class="iscope-a; iscope-b"></div>'); - }).toThrow('[$compile:multidir] Multiple directives [iscopeA, iscopeB] asking for isolated scope on: ' + + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [iscopeA, iscopeB] asking for isolated scope on: ' + '<div class="iscope-a; iscope-b ng-isolate-scope ng-scope">'); }) ); @@ -2110,7 +2110,7 @@ describe('$compile', function() { componentScope.ref = 'ignore me'; expect($rootScope.$apply). - toThrow("[$compile:nonassign] Expression ''hello ' + name' used with directive 'myComponent' is non-assignable!"); + toThrowMinErr("$compile", "nonassign", "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; @@ -2186,7 +2186,7 @@ describe('$compile', function() { it('should throw on unknown definition', inject(function() { expect(function() { compile('<div><span bad-declaration>'); - }).toThrow("[$compile:iscp] Invalid isolate scope definition for directive 'badDeclaration'. Definition: {... attr: 'xxx' ...}"); + }).toThrowMinErr("$compile", "iscp", "Invalid isolate scope definition for directive 'badDeclaration'. Definition: {... attr: 'xxx' ...}"); })); it('should expose a $$isolateBindings property onto the scope', inject(function() { @@ -2329,7 +2329,7 @@ describe('$compile', function() { inject(function(log, $compile, $rootScope) { expect(function() { $compile('<div main><div dep></div></div>')($rootScope); - }).toThrow("[$compile:ctreq] Controller 'main', required by directive 'dep', can't be found!"); + }).toThrowMinErr("$compile", "ctreq", "Controller 'main', required by directive 'dep', can't be found!"); }); }); @@ -2724,7 +2724,7 @@ describe('$compile', function() { inject(function($compile) { expect(function() { $compile('<div class="first second"></div>'); - }).toThrow('[$compile:multidir] Multiple directives [first, second] asking for transclusion on: ' + + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [first, second] asking for transclusion on: ' + '<div class="first second ng-isolate-scope ng-scope">'); }); }); @@ -3147,18 +3147,18 @@ describe('$compile', function() { $rootScope.onClickJs = ""; expect(function() { $compile('<button onclick="{{onClickJs}}"></script>')($rootScope); - }).toThrow( - "[$compile:nodomevents] Interpolations for HTML DOM event attributes are disallowed. " + + }).toThrowMinErr( + "$compile", "nodomevents", "Interpolations for HTML DOM event attributes are disallowed. " + "Please use the ng- versions (such as ng-click instead of onclick) instead."); expect(function() { $compile('<button ONCLICK="{{onClickJs}}"></script>')($rootScope); - }).toThrow( - "[$compile:nodomevents] Interpolations for HTML DOM event attributes are disallowed. " + + }).toThrowMinErr( + "$compile", "nodomevents", "Interpolations for HTML DOM event attributes are disallowed. " + "Please use the ng- versions (such as ng-click instead of onclick) instead."); expect(function() { $compile('<button ng-attr-onclick="{{onClickJs}}"></script>')($rootScope); - }).toThrow( - "[$compile:nodomevents] Interpolations for HTML DOM event attributes are disallowed. " + + }).toThrowMinErr( + "$compile", "nodomevents", "Interpolations for HTML DOM event attributes are disallowed. " + "Please use the ng- versions (such as ng-click instead of onclick) instead."); })); @@ -3181,8 +3181,8 @@ describe('$compile', function() { it('should clear out src attributes for a different domain', inject(function($compile, $rootScope, $sce) { element = $compile('<iframe src="{{testUrl}}"></iframe>')($rootScope); $rootScope.testUrl = "http://a.different.domain.example.com"; - expect(function() { $rootScope.$apply() }).toThrow( - "[$interpolate:interr] Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + + expect(function() { $rootScope.$apply() }).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: " + "http://a.different.domain.example.com"); })); @@ -3190,8 +3190,8 @@ describe('$compile', function() { it('should clear out JS src attributes', inject(function($compile, $rootScope, $sce) { element = $compile('<iframe src="{{testUrl}}"></iframe>')($rootScope); $rootScope.testUrl = "javascript:alert(1);"; - expect(function() { $rootScope.$apply() }).toThrow( - "[$interpolate:interr] Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + + expect(function() { $rootScope.$apply() }).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: " + "javascript:alert(1);"); })); @@ -3199,8 +3199,8 @@ describe('$compile', function() { it('should clear out non-resource_url src attributes', inject(function($compile, $rootScope, $sce) { element = $compile('<iframe src="{{testUrl}}"></iframe>')($rootScope); $rootScope.testUrl = $sce.trustAsUrl("javascript:doTrustedStuff()"); - expect($rootScope.$apply).toThrow( - "[$interpolate:interr] Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + + expect($rootScope.$apply).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: javascript:doTrustedStuff()"); })); @@ -3347,7 +3347,7 @@ describe('$compile', function() { '<div>' + '<span foo-start></span>' + '</div>'); - }).toThrow("[$compile:uterdir] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); + }).toThrowMinErr("$compile", "uterdir", "Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); }); }); @@ -3365,7 +3365,7 @@ describe('$compile', function() { '<div>' + '<span foo-start><span foo-end></span></span>' + '</div>'); - }).toThrow("[$compile:uterdir] Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); + }).toThrowMinErr("$compile", "uterdir", "Unterminated attribute, found 'foo-start' but no matching 'foo-end' found."); }); }); diff --git a/test/ng/controllerSpec.js b/test/ng/controllerSpec.js index 6446ecf9..2a9922c6 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("[$controller:noscp] Cannot export controller 'a.b.FooCtrl' as 'foo'! No $scope object provided via `locals`."); + }).toThrowMinErr("$controller", "noscp", "Cannot export controller 'a.b.FooCtrl' as 'foo'! No $scope object provided via `locals`."); }); }); diff --git a/test/ng/directive/booleanAttrsSpec.js b/test/ng/directive/booleanAttrsSpec.js index 82639051..83bc75e5 100644 --- a/test/ng/directive/booleanAttrsSpec.js +++ b/test/ng/directive/booleanAttrsSpec.js @@ -93,7 +93,7 @@ describe('boolean attr directives', function() { expect(function() { $compile('<select multiple="{{isMultiple}}"></select>') - }).toThrow('[$compile:selmulti] Binding to the \'multiple\' attribute is not supported. ' + + }).toThrowMinErr('$compile', 'selmulti', 'Binding to the \'multiple\' attribute is not supported. ' + 'Element: <select multiple="{{isMultiple}}">'); })); @@ -137,8 +137,8 @@ describe('ngSrc', function() { expect(function() { var element = $compile('<div ng-src="some/{{id}}"></div>')($rootScope); dealoc(element); - }).toThrow( - "[$interpolate:noconcat] Error while interpolating: some/{{id}}\nStrict " + + }).toThrowMinErr( + "$interpolate", "noconcat", "Error while interpolating: some/{{id}}\nStrict " + "Contextual Escaping disallows interpolations that concatenate multiple expressions " + "when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce"); })); @@ -162,8 +162,8 @@ describe('ngSrc', function() { $rootScope.id = $sce.trustAsUrl('http://somewhere'); }); element.attr('src'); - }).toThrow( - "[$interpolate:interr] Can't interpolate: {{id}}\nError: [$sce:insecurl] Blocked " + + }).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{id}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: http://somewhere"); })); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index a69a4195..facc2b80 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -43,7 +43,7 @@ describe('NgModelController', function() { } expect(exception.message). - toMatch(/^\[ngModel:nonassign\] Expression '1\+2' is non\-assignable\. Element: <input( value="")? ng-model="1\+2">$/); + toMatch(/^\[ngModel:nonassign\] Expression '1\+2' is non\-assignable\. Element: <input( value="")? ng-model="1\+2">/); })); @@ -457,7 +457,7 @@ describe('input', function() { expect(function() { compileInput('<input type="text" ng-model="throw \'\'">'); scope.$digest(); - }).toThrow("[$parse:syntax] Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); + }).toThrowMinErr("$parse", "syntax", "Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); }); diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 35b9f897..fc41bc6d 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -77,7 +77,7 @@ describe('ngRepeat', function() { expect(element.find('li').length).toEqual(3); expect(element.text()).toEqual('x;y;x;'); }); - + it('should iterate over an array-like class', function() { function Collection() {} Collection.prototype = new Array(); @@ -350,7 +350,7 @@ describe('ngRepeat', function() { element = jqLite('<ul><li ng-repeat="i dont parse"></li></ul>'); $compile(element)(scope); expect($exceptionHandler.errors.shift()[0].message). - toBe("[ngRepeat:iexp] Expected expression in form of '_item_ in _collection_[ track by _id_]' but got 'i dont parse'."); + toMatch(/^\[ngRepeat:iexp\] Expected expression in form of '_item_ in _collection_\[ track by _id_\]' but got 'i dont parse'\./); }); @@ -358,7 +358,7 @@ describe('ngRepeat', function() { element = jqLite('<ul><li ng-repeat="i dont parse in foo"></li></ul>'); $compile(element)(scope); expect($exceptionHandler.errors.shift()[0].message). - toBe("[ngRepeat:iidexp] '_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got 'i dont parse'."); + toMatch(/^\[ngRepeat:iidexp\] '_item_' in '_item_ in _collection_' should be an identifier or '\(_key_, _value_\)' expression, but got 'i dont parse'\./); }); @@ -773,7 +773,7 @@ describe('ngRepeat', function() { scope.items = [a, a, a]; scope.$digest(); expect($exceptionHandler.errors.shift().message). - 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"); + toMatch(/^\[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]; @@ -793,7 +793,7 @@ describe('ngRepeat', function() { scope.items = [d, d, d]; scope.$digest(); expect($exceptionHandler.errors.shift().message). - 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"); + toMatch(/^\[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/ngSrcSpec.js b/test/ng/directive/ngSrcSpec.js index 2fb99eab..3dc00257 100644 --- a/test/ng/directive/ngSrcSpec.js +++ b/test/ng/directive/ngSrcSpec.js @@ -26,8 +26,8 @@ describe('ngSrc', function() { it('should error on src attributes for a different domain', inject(function($compile, $rootScope) { element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($rootScope); $rootScope.testUrl = "http://a.different.domain.example.com"; - expect(function() { $rootScope.$apply() }).toThrow( - "[$interpolate:interr] Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + + expect(function() { $rootScope.$apply() }).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: " + "http://a.different.domain.example.com"); })); @@ -35,8 +35,8 @@ describe('ngSrc', function() { it('should error on JS src attributes', inject(function($compile, $rootScope) { element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($rootScope); $rootScope.testUrl = "javascript:alert(1);"; - expect(function() { $rootScope.$apply() }).toThrow( - "[$interpolate:interr] Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + + expect(function() { $rootScope.$apply() }).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: " + "javascript:alert(1);"); })); @@ -44,8 +44,8 @@ describe('ngSrc', function() { it('should error on non-resource_url src attributes', inject(function($compile, $rootScope, $sce) { element = $compile('<iframe ng-src="{{testUrl}}"></iframe>')($rootScope); $rootScope.testUrl = $sce.trustAsUrl("javascript:doTrustedStuff()"); - expect($rootScope.$apply).toThrow( - "[$interpolate:interr] Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + + expect($rootScope.$apply).toThrowMinErr( + "$interpolate", "interr", "Can't interpolate: {{testUrl}}\nError: [$sce:insecurl] Blocked " + "loading resource from url not allowed by $sceDelegate policy. URL: " + "javascript:doTrustedStuff()"); })); diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 5be7eb65..5906ce99 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -494,7 +494,7 @@ describe('select', function() { it('should throw when not formated "? for ? in ?"', function() { expect(function() { compile('<select ng-model="selected" ng-options="i dont parse"></select>'); - }).toThrowMatching(/^\[ngOptions:iexp\] Expected expression in form of/); + }).toThrowMinErr('ngOptions', 'iexp', /Expected expression in form of/); }); diff --git a/test/ng/interpolateSpec.js b/test/ng/interpolateSpec.js index d74b764a..60612329 100644 --- a/test/ng/interpolateSpec.js +++ b/test/ng/interpolateSpec.js @@ -32,7 +32,7 @@ describe('$interpolate', function() { }; expect(function () { $interpolate('{{err()}}')($rootScope); - }).toThrow("[$interpolate:interr] Can't interpolate: {{err()}}\nError: oops"); + }).toThrowMinErr("$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("[$interpolate:interr] Can't interpolate: {{err()}}\nError: oops"); + }).toThrowMinErr("$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}}'); @@ -107,8 +107,8 @@ describe('$interpolate', function() { var bar = sce.trustAsCss("bar"); expect(function() { return $interpolate('{{foo}}{{bar}}', true, sce.CSS)( - {foo: foo, bar: bar}); }).toThrow( - "[$interpolate:noconcat] Error while interpolating: {{foo}}{{bar}}\n" + + {foo: foo, bar: bar}); }).toThrowMinErr( + "$interpolate", "noconcat", "Error while interpolating: {{foo}}{{bar}}\n" + "Strict Contextual Escaping disallows interpolations that concatenate multiple " + "expressions when a trusted value is required. See " + "http://docs.angularjs.org/api/ng.$sce"); @@ -203,14 +203,14 @@ describe('$interpolate', function() { var isTrustedContext = true; expect(function() { $interpolate('constant/{{var}}', true, isTrustedContext); - }).toThrow( - "[$interpolate:noconcat] Error while interpolating: constant/{{var}}\nStrict " + + }).toThrowMinErr( + "$interpolate", "noconcat", "Error while interpolating: constant/{{var}}\nStrict " + "Contextual Escaping disallows interpolations that concatenate multiple expressions " + "when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce"); expect(function() { $interpolate('{{foo}}{{bar}}', true, isTrustedContext); - }).toThrow( - "[$interpolate:noconcat] Error while interpolating: {{foo}}{{bar}}\nStrict " + + }).toThrowMinErr( + "$interpolate", "noconcat", "Error while interpolating: {{foo}}{{bar}}\nStrict " + "Contextual Escaping disallows interpolations that concatenate multiple expressions " + "when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce"); })); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index a07b516b..a60f1609 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -88,10 +88,10 @@ describe('$location', function() { it('search() should throw error an incorrect argument', function() { expect(function() { url.search(null); - }).toThrow('[$location:isrcharg] The first argument of the `$location#search()` call must be a string or an object.'); + }).toThrowMinErr('$location', 'isrcharg', 'The first argument of the `$location#search()` call must be a string or an object.'); expect(function() { url.search(undefined); - }).toThrow('[$location:isrcharg] The first argument of the `$location#search()` call must be a string or an object.'); + }).toThrowMinErr('$location', 'isrcharg', 'The first argument of the `$location#search()` call must be a string or an object.'); }); @@ -219,7 +219,7 @@ describe('$location', function() { expect(function() { url.$$parse('http://other.server.org/path#/path'); - }).toThrow('[$location:ipthprfx] Invalid url "http://other.server.org/path#/path", missing path prefix "http://server.org/base/".'); + }).toThrowMinErr('$location', 'ipthprfx', 'Invalid url "http://other.server.org/path#/path", missing path prefix "http://server.org/base/".'); }); @@ -228,7 +228,7 @@ describe('$location', function() { expect(function() { url.$$parse('http://server.org/path#/path'); - }).toThrow('[$location:ipthprfx] Invalid url "http://server.org/path#/path", missing path prefix "http://server.org/base/".'); + }).toThrowMinErr('$location', 'ipthprfx', 'Invalid url "http://server.org/path#/path", missing path prefix "http://server.org/base/".'); }); @@ -341,7 +341,7 @@ describe('$location', function() { it('should throw error when invalid hashbang prefix given', function() { expect(function() { url.$$parse('http://www.server.org:1234/base#/path'); - }).toThrow('[$location:ihshprfx] Invalid url "http://www.server.org:1234/base#/path", missing hash prefix "#!".'); + }).toThrowMinErr('$location', 'ihshprfx', '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 568a3b15..f9a80fb6 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('[$parse:lexerr] Lexer Error: Invalid exponent at column 4 in expression [0.5E-].')); + }).toThrowMinErr('$parse', 'lexerr', 'Lexer Error: Invalid exponent at column 4 in expression [0.5E-].'); expect(function() { lex("0.5E-A"); - }).toThrow(new Error('[$parse:lexerr] Lexer Error: Invalid exponent at column 4 in expression [0.5E-A].')); + }).toThrowMinErr('$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("[$parse:lexerr] Lexer Error: Invalid unicode escape [\\u1''b] at column 2 in expression ['\\u1''bla'].")); + }).toThrowMinErr("$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("[$injector:unpr] Unknown provider: nonexistentFilterProvider <- nonexistentFilter")); + }).toThrowMinErr('$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('[$parse:ueoe] Unexpected end of expression: [].count('); + }).toThrowMinErr('$parse', 'ueoe', 'Unexpected end of expression: [].count('); }); it('should evaluate double negation', function() { @@ -558,86 +558,86 @@ describe('parser', function() { it('should NOT allow access to Function constructor in getter', function() { expect(function() { scope.$eval('{}.toString.constructor'); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: {}.toString.constructor')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: {}.toString.constructor'); expect(function() { scope.$eval('{}.toString.constructor("alert(1)")'); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: {}.toString.constructor("alert(1)")')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: {}.toString.constructor("alert(1)")'); expect(function() { scope.$eval('[].toString.constructor.foo'); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: [].toString.constructor.foo')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: [].toString.constructor.foo'); expect(function() { scope.$eval('{}.toString["constructor"]'); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: {}.toString["constructor"]')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: {}.toString["constructor"]'); expect(function() { scope.$eval('{}["toString"]["constructor"]'); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: {}["toString"]["constructor"]')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: {}["toString"]["constructor"]'); scope.a = []; expect(function() { scope.$eval('a.toString.constructor', scope); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: a.toString.constructor')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: a.toString.constructor'); expect(function() { scope.$eval('a.toString["constructor"]', scope); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: a.toString["constructor"]')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: a.toString["constructor"]'); }); it('should NOT allow access to Function constructor in setter', function() { expect(function() { scope.$eval('{}.toString.constructor = 1'); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: {}.toString.constructor = 1')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: {}.toString.constructor = 1'); expect(function() { scope.$eval('{}.toString.constructor.a = 1'); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: {}.toString.constructor.a = 1')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: {}.toString.constructor.a = 1'); expect(function() { scope.$eval('{}.toString["constructor"]["constructor"] = 1'); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: {}.toString["constructor"]["constructor"] = 1')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: {}.toString["constructor"]["constructor"] = 1'); scope.key1 = "const"; scope.key2 = "ructor"; expect(function() { scope.$eval('{}.toString[key1 + key2].foo = 1'); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: {}.toString[key1 + key2].foo = 1')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: {}.toString[key1 + key2].foo = 1'); expect(function() { scope.$eval('{}.toString["constructor"]["a"] = 1'); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: {}.toString["constructor"]["a"] = 1')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: {}.toString["constructor"]["a"] = 1'); scope.a = []; expect(function() { scope.$eval('a.toString.constructor = 1', scope); - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: a.toString.constructor = 1')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: a.toString.constructor = 1'); }); @@ -645,9 +645,9 @@ describe('parser', function() { scope.foo = { "bar": Function }; expect(function() { scope.$eval('foo["bar"]'); - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: foo["bar"]')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: foo["bar"]'); }); }); @@ -661,14 +661,14 @@ describe('parser', function() { // index operator. expect(function() { scope.$eval('foo.constructor()', scope) - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: foo.constructor()')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: foo.constructor()'); expect(function() { scope.$eval('foo["constructor"]()', scope) - }).toThrow(new Error( - '[$parse:isecfn] Referencing Function in Angular expressions is disallowed! ' + - 'Expression: foo["constructor"]()')); + }).toThrowMinErr( + '$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' + + 'Expression: foo["constructor"]()'); // User defined value assigned to constructor. scope.foo.constructor = function constructor() { @@ -677,9 +677,9 @@ describe('parser', function() { // Dot operator should still block it. expect(function() { scope.$eval('foo.constructor()', scope) - }).toThrow(new Error( - '[$parse:isecfld] Referencing "constructor" field in Angular expressions is disallowed! ' + - 'Expression: foo.constructor()')); + }).toThrowMinErr( + '$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions is disallowed! ' + + 'Expression: foo.constructor()'); // However, the index operator should allow it. expect(scope.$eval('foo["constructor"]()', scope)).toBe('custom constructor'); }); @@ -864,10 +864,10 @@ describe('parser', function() { })); - it('should evaluate a resolved primitive type promise and set its value', inject(function($parse) { + it('should evaluate a resolved primitive type promise and set its value', inject(function($parse) { scope.greeting = promise; deferred.resolve('Salut!'); - + var getter = $parse('greeting'); expect(getter(scope)).toBe(undefined); diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 049258cf..ddd83088 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -215,7 +215,7 @@ describe('Scope', function() { expect(function() { $rootScope.$digest(); - }).toThrow('[$rootScope:infdig] 100 $digest() iterations reached. Aborting!\n'+ + }).toThrowMinErr('$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('[$rootScope:inprog] $digest already in progress'); + }).toThrowMinErr('$rootScope', 'inprog', '$digest already in progress'); callCount++; }); $rootScope.name = 'a'; @@ -796,7 +796,7 @@ describe('Scope', function() { $rootScope.$apply(function() { $rootScope.$apply(); }); - }).toThrow('[$rootScope:inprog] $apply already in progress'); + }).toThrowMinErr('$rootScope', 'inprog', '$apply already in progress'); })); @@ -808,7 +808,7 @@ describe('Scope', function() { $rootScope.$apply(); }); }); - }).toThrow('[$rootScope:inprog] $digest already in progress'); + }).toThrowMinErr('$rootScope', 'inprog', '$digest already in progress'); })); @@ -818,7 +818,7 @@ describe('Scope', function() { childScope1.$watch('x', function() { childScope1.$apply(); }); - expect(function() { childScope1.$apply(); }).toThrow('[$rootScope:inprog] $digest already in progress'); + expect(function() { childScope1.$apply(); }).toThrowMinErr('$rootScope', 'inprog', '$digest already in progress'); })); @@ -835,7 +835,7 @@ describe('Scope', function() { expect(function() { childScope2.$apply(function() { childScope2.x = 'something'; - }); }).toThrow('[$rootScope:inprog] $digest already in progress'); + }); }).toThrowMinErr('$rootScope', 'inprog', '$digest already in progress'); })); }); }); diff --git a/test/ng/sceSpecs.js b/test/ng/sceSpecs.js index 9be794fb..75c1fbaa 100644 --- a/test/ng/sceSpecs.js +++ b/test/ng/sceSpecs.js @@ -41,8 +41,8 @@ describe('SCE', function() { try { $window.msie = true; if (expectException) { - expect(constructSce).toThrow( - '[$sce:iequirks] Strict Contextual Escaping does not support Internet Explorer ' + + expect(constructSce).toThrowMinErr( + '$sce', 'iequirks', 'Strict Contextual Escaping does not support Internet Explorer ' + 'version < 9 in quirks mode. You can fix this by adding the text <!doctype html> to ' + 'the top of your HTML document. See http://docs.angularjs.org/api/ng.$sce for more ' + 'information.'); @@ -88,13 +88,13 @@ describe('SCE', function() { var wrappedValue = $sce.trustAs($sce.HTML, originalValue); expect(typeof wrappedValue).toBe('object'); expect($sce.getTrusted($sce.HTML, wrappedValue)).toBe('original_value'); - expect(function() { $sce.getTrusted($sce.CSS, wrappedValue); }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + expect(function() { $sce.getTrusted($sce.CSS, wrappedValue); }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); wrappedValue = $sce.trustAs($sce.CSS, originalValue); expect(typeof wrappedValue).toBe('object'); expect($sce.getTrusted($sce.CSS, wrappedValue)).toBe('original_value'); - expect(function() { $sce.getTrusted($sce.HTML, wrappedValue); }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + expect(function() { $sce.getTrusted($sce.HTML, wrappedValue); }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); wrappedValue = $sce.trustAs($sce.URL, originalValue); expect(typeof wrappedValue).toBe('object'); expect($sce.getTrusted($sce.URL, wrappedValue)).toBe('original_value'); @@ -104,19 +104,19 @@ describe('SCE', function() { })); it('should NOT wrap non-string values', inject(function($sce) { - expect(function() { $sce.trustAsCss(123); }).toThrow( - '[$sce:itype] Attempted to trust a non-string value in a content requiring a string: ' + + expect(function() { $sce.trustAsCss(123); }).toThrowMinErr( + '$sce', 'itype', 'Attempted to trust a non-string value in a content requiring a string: ' + 'Context: css'); })); it('should NOT wrap unknown contexts', inject(function($sce) { - expect(function() { $sce.trustAs('unknown1' , '123'); }).toThrow( - '[$sce:icontext] Attempted to trust a value in invalid context. Context: unknown1; Value: 123'); + expect(function() { $sce.trustAs('unknown1' , '123'); }).toThrowMinErr( + '$sce', 'icontext', 'Attempted to trust a value in invalid context. Context: unknown1; Value: 123'); })); it('should NOT wrap undefined context', inject(function($sce) { - expect(function() { $sce.trustAs(undefined, '123'); }).toThrow( - '[$sce:icontext] Attempted to trust a value in invalid context. Context: undefined; Value: 123'); + expect(function() { $sce.trustAs(undefined, '123'); }).toThrowMinErr( + '$sce', 'icontext', 'Attempted to trust a value in invalid context. Context: undefined; Value: 123'); })); it('should wrap undefined into undefined', inject(function($sce) { @@ -156,8 +156,8 @@ describe('SCE', function() { it('should NOT unwrap values when the type is different', inject(function($sce) { var originalValue = "originalValue"; var wrappedValue = $sce.trustAs($sce.HTML, originalValue); - expect(function () { $sce.getTrusted($sce.CSS, wrappedValue); }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + expect(function () { $sce.getTrusted($sce.CSS, wrappedValue); }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); })); it('should NOT unwrap values that had not been wrapped', inject(function($sce) { @@ -167,8 +167,8 @@ describe('SCE', function() { }; } var wrappedValue = new TrustedValueHolder("originalValue"); - expect(function() { return $sce.getTrusted($sce.HTML, wrappedValue) }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + expect(function() { return $sce.getTrusted($sce.HTML, wrappedValue) }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); })); it('should implement toString on trusted values', inject(function($sce) { @@ -224,16 +224,16 @@ describe('SCE', function() { var exprFn = $sce.parseAs($sce.HTML, 'foo'); expect(function() { return exprFn({}, {'foo': true}) - }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); })); it('should NOT return trusted values of the wrong type from expression function', inject(function($sce) { var exprFn = $sce.parseAs($sce.HTML, 'foo'); expect(function() { return exprFn({}, {'foo': $sce.trustAs($sce.JS, '123')}) - }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); })); it('should return trusted values from expression function', inject(function($sce) { @@ -249,8 +249,8 @@ describe('SCE', function() { expect(function() { // mismatched types. $sce.parseAsCss('foo')({}, {'foo': $sce.trustAsHtml('1')}); - }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); })); }); @@ -279,8 +279,8 @@ describe('SCE', function() { whiteList: [], blackList: [] }, function($sce) { - expect(function() { $sce.getTrustedResourceUrl('#'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: #'); + expect(function() { $sce.getTrustedResourceUrl('#'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: #'); })); it('should match against normalized urls', runTest( @@ -288,8 +288,8 @@ describe('SCE', function() { whiteList: [/^foo$/], blackList: [] }, function($sce) { - expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo'); + expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo'); })); it('should support custom regex', runTest( @@ -298,8 +298,8 @@ describe('SCE', function() { blackList: [] }, function($sce) { expect($sce.getTrustedResourceUrl('http://example.com/foo')).toEqual('http://example.com/foo'); - expect(function() { $sce.getTrustedResourceUrl('https://example.com/foo'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: https://example.com/foo'); + expect(function() { $sce.getTrustedResourceUrl('https://example.com/foo'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: https://example.com/foo'); })); it('should support the special string "self" in whitelist', runTest( @@ -315,8 +315,8 @@ describe('SCE', function() { whiteList: [/.*/], blackList: ['self'] }, function($sce) { - expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo'); + expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo'); })); it('should have blacklist override the whitelist', runTest( @@ -324,8 +324,8 @@ describe('SCE', function() { whiteList: ['self'], blackList: ['self'] }, function($sce) { - expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo'); + expect(function() { $sce.getTrustedResourceUrl('foo'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: foo'); })); it('should support multiple items in both lists', runTest( @@ -336,18 +336,18 @@ describe('SCE', function() { expect($sce.getTrustedResourceUrl('same_domain')).toEqual('same_domain'); expect($sce.getTrustedResourceUrl('http://example.com/1')).toEqual('http://example.com/1'); expect($sce.getTrustedResourceUrl('http://example.com/2')).toEqual('http://example.com/2'); - expect(function() { $sce.getTrustedResourceUrl('http://example.com/3'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/3'); - expect(function() { $sce.getTrustedResourceUrl('open_redirect'); }).toThrow( - '[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: open_redirect'); + expect(function() { $sce.getTrustedResourceUrl('http://example.com/3'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/3'); + expect(function() { $sce.getTrustedResourceUrl('open_redirect'); }).toThrowMinErr( + '$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: open_redirect'); })); }); describe('sanitizing html', function() { describe('when $sanitize is NOT available', function() { it('should throw an exception for getTrusted(string) values', inject(function($sce) { - expect(function() { $sce.getTrustedHtml('<b></b>'); }).toThrow( - '[$sce:unsafe] Attempting to use an unsafe value in a safe context.'); + expect(function() { $sce.getTrustedHtml('<b></b>'); }).toThrowMinErr( + '$sce', 'unsafe', 'Attempting to use an unsafe value in a safe context.'); })); }); diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index 68c1b171..d971e8e7 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -877,8 +877,8 @@ describe("resource", function() { expect(user).toEqualData([ {id: 1, name: 'user1'} ]); }); }); - - describe('get', function(){ + + describe('get', function(){ it('should add them to the id', function() { $httpBackend.expect('GET', '/users/1.json').respond({id: 1, name: 'user1'}); var UserService = $resource('/users/:user_id.json', {user_id: '@id'}); @@ -908,7 +908,7 @@ describe("resource", function() { var UserService = $resource('/users/:user_id', {user_id: '@id'}, { get: { method: 'GET', - url: '/users/:user_id.json' + url: '/users/:user_id.json' } }); var user = UserService.get({user_id: 1}); @@ -1036,13 +1036,13 @@ describe("resource", function() { describe('resource', function() { var $httpBackend, $resource; - + beforeEach(module(function($exceptionHandlerProvider) { $exceptionHandlerProvider.mode('log'); })); - + beforeEach(module('ngResource')); - + beforeEach(inject(function($injector) { $httpBackend = $injector.get('$httpBackend'); $resource = $injector.get('$resource'); @@ -1054,14 +1054,16 @@ describe('resource', function() { var failureSpy = jasmine.createSpy('failureSpy'); $httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'}); - + $resource('/Customer/123').query() .$promise.then(successSpy, function(e) { failureSpy(e.message); }); $httpBackend.flush(); expect(successSpy).not.toHaveBeenCalled(); - expect(failureSpy).toHaveBeenCalledWith( - '[$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object'); + expect(failureSpy).toHaveBeenCalled(); + expect(failureSpy.mostRecentCall.args[0]).toMatch( + /^\[\$resource:badcfg\] Error in resource configuration\. Expected response to contain an array but got an object/ + ); }); it('should fail if action expects an array but response is an object', function() { @@ -1069,14 +1071,16 @@ describe('resource', function() { var failureSpy = jasmine.createSpy('failureSpy'); $httpBackend.expect('GET', '/Customer/123').respond([1,2,3]); - + $resource('/Customer/123').get() .$promise.then(successSpy, function(e) { failureSpy(e.message); }); $httpBackend.flush(); expect(successSpy).not.toHaveBeenCalled(); - expect(failureSpy).toHaveBeenCalledWith( - '[$resource:badcfg] Error in resource configuration. Expected response to contain an object but got an array'); + expect(failureSpy).toHaveBeenCalled(); + expect(failureSpy.mostRecentCall.args[0]).toMatch( + /^\[\$resource:badcfg\] Error in resource configuration. Expected response to contain an object but got an array/ + ) }); diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 0064c26c..ae9883a2 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -545,7 +545,8 @@ describe('$route', function() { $location.path('/foo'); expect(function() { $rootScope.$digest(); - }).toThrow('[$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/foo.html'); + }).toThrowMinErr('$sce', 'insecurl', 'Blocked loading resource from url not allowed by ' + + '$sceDelegate policy. URL: http://example.com/foo.html'); }); }); |
