Unified
Split
Showing
with
150 additions
and 126 deletions.
- +7 −10 test/AngularSpec.js
- +1 −1 test/auto/injectorSpec.js
- +66 −44 test/helpers/matchers.js
- +1 −1 test/jqLiteSpec.js
- +31 −26 test/ng/compileSpec.js
- +18 −17 test/ng/directive/ngRepeatSpec.js
- +2 −2 test/ng/directive/validatorsSpec.js
- +7 −7 test/ng/httpSpec.js
- +2 −2 test/ng/qSpec.js
- +4 −6 test/ng/templateRequestSpec.js
- +6 −6 test/ngResource/resourceSpec.js
- +5 −4 test/ngRoute/routeSpec.js
| @@ -1636,8 +1636,8 @@ describe('angular', function() { | ||
|
|
||
| expect(function() { | ||
| angularInit(appElement, angular.bootstrap); | ||
| }).toThrowError( | ||
| new RegExp('\\[\\$injector:modulerr] Failed to instantiate module doesntexist due to:\\n' + | ||
| }).toThrowMinErr('$injector', 'modulerr', | ||
| new RegExp('Failed to instantiate module doesntexist due to:\\n' + | ||
| '.*\\[\\$injector:nomod] Module \'doesntexist\' is not available! You either ' + | ||
| 'misspelled the module name or forgot to load it\\.') | ||
| ); | ||
| @@ -1650,9 +1650,8 @@ describe('angular', function() { | ||
|
|
||
| expect(function() { | ||
| angular.bootstrap(element); | ||
| }).toThrowError( | ||
| /\[ng:btstrpd\] App Already Bootstrapped with this Element '<div class="?ng\-scope"?( ng[0-9]+="?[0-9]+"?)?>'/i | ||
| ); | ||
| }).toThrowMinErr('ng', 'btstrpd', | ||
| /App Already Bootstrapped with this Element '<div class="?ng-scope"?( ng\d+="?\d+"?)?>'/i); | ||
|
|
||
| dealoc(element); | ||
| }); | ||
| @@ -1662,9 +1661,7 @@ describe('angular', function() { | ||
| angular.bootstrap(document.getElementsByTagName('html')[0]); | ||
| expect(function() { | ||
| angular.bootstrap(document); | ||
| }).toThrowError( | ||
| /\[ng:btstrpd\] App Already Bootstrapped with this Element 'document'/i | ||
| ); | ||
| }).toThrowMinErr('ng', 'btstrpd', /App Already Bootstrapped with this Element 'document'/i); | ||
|
|
||
| dealoc(document); | ||
| }); | ||
| @@ -1863,8 +1860,8 @@ describe('angular', function() { | ||
|
|
||
| expect(function() { | ||
| angular.bootstrap(element, ['doesntexist']); | ||
| }).toThrowError( | ||
| new RegExp('\\[\\$injector:modulerr\\] Failed to instantiate module doesntexist due to:\\n' + | ||
| }).toThrowMinErr('$injector', 'modulerr', | ||
| new RegExp('Failed to instantiate module doesntexist due to:\\n' + | ||
| '.*\\[\\$injector:nomod\\] Module \'doesntexist\' is not available! You either ' + | ||
| 'misspelled the module name or forgot to load it\\.')); | ||
|
|
||
| @@ -1062,7 +1062,7 @@ describe('injector', function() { | ||
| createInjector([function($provide) { | ||
| $provide.value('name', 'angular'); | ||
| }, instanceLookupInModule]); | ||
| }).toThrowError(/\[\$injector:unpr] Unknown provider: name/); | ||
| }).toThrowMinErr('$injector', 'modulerr', '[$injector:unpr] Unknown provider: name'); | ||
| }); | ||
| }); | ||
| }); | ||
| @@ -49,6 +49,41 @@ beforeEach(function() { | ||
| return hidden; | ||
| } | ||
|
|
||
| function MinErrMatcher(isNot, namespace, code, content, wording) { | ||
| var codeRegex = new RegExp('^' + escapeRegexp('[' + namespace + ':' + code + ']')); | ||
| var contentRegex = angular.isUndefined(content) || jasmine.isA_('RegExp', content) ? | ||
| content : new RegExp(escapeRegexp(content)); | ||
|
|
||
| this.test = test; | ||
|
|
||
| function escapeRegexp(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, '\\$&'); | ||
| } | ||
|
|
||
| function test(exception) { | ||
| var exceptionMessage = (exception && exception.message) || exception || ''; | ||
|
|
||
| var codeMatches = codeRegex.test(exceptionMessage); | ||
| var contentMatches = angular.isUndefined(contentRegex) || contentRegex.test(exceptionMessage); | ||
| var matches = codeMatches && contentMatches; | ||
|
|
||
| return { | ||
| pass: isNot ? !matches : matches, | ||
| message: message | ||
| }; | ||
|
|
||
| function message() { | ||
| return 'Expected ' + wording.inputType + (isNot ? ' not' : '') + ' to ' + | ||
| wording.expectedAction + ' ' + namespace + 'MinErr(\'' + code + '\')' + | ||
| (contentRegex ? ' matching ' + contentRegex.toString() : '') + | ||
| (!exception ? '.' : ', but it ' + wording.actualAction + ': ' + exceptionMessage); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| jasmine.addMatchers({ | ||
| toBeEmpty: cssMatcher('ng-empty', 'ng-not-empty'), | ||
| toBeNotEmpty: cssMatcher('ng-not-empty', 'ng-empty'), | ||
| @@ -58,6 +93,7 @@ beforeEach(function() { | ||
| toBePristine: cssMatcher('ng-pristine', 'ng-dirty'), | ||
| toBeUntouched: cssMatcher('ng-untouched', 'ng-touched'), | ||
| toBeTouched: cssMatcher('ng-touched', 'ng-untouched'), | ||
|
|
||
| toBeAPromise: function() { | ||
| return { | ||
| compare: generateCompare(false), | ||
| @@ -71,6 +107,7 @@ beforeEach(function() { | ||
| }; | ||
| } | ||
| }, | ||
|
|
||
| toBeShown: function() { | ||
| return { | ||
| compare: generateCompare(false), | ||
| @@ -87,6 +124,7 @@ beforeEach(function() { | ||
| }; | ||
| } | ||
| }, | ||
|
|
||
| toBeHidden: function() { | ||
| return { | ||
| compare: generateCompare(false), | ||
| @@ -267,26 +305,34 @@ beforeEach(function() { | ||
| } | ||
| }, | ||
|
|
||
| toEqualMinErr: function() { | ||
| return { | ||
| compare: generateCompare(false), | ||
| negativeCompare: generateCompare(true) | ||
| }; | ||
|
|
||
| function generateCompare(isNot) { | ||
| return function(actual, namespace, code, content) { | ||
| var matcher = new MinErrMatcher(isNot, namespace, code, content, { | ||
| inputType: 'error', | ||
| expectedAction: 'equal', | ||
| actualAction: 'was' | ||
| }); | ||
|
|
||
| return matcher.test(actual); | ||
| }; | ||
| } | ||
| }, | ||
|
|
||
| toThrowMinErr: function() { | ||
| return { | ||
| compare: generateCompare(false), | ||
| negativeCompare: generateCompare(true) | ||
| }; | ||
|
|
||
| function generateCompare(isNot) { | ||
| return function(actual, 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 = isNot ? 'not ' : '', | ||
| regex = jasmine.isA_('RegExp', content) ? content : | ||
| angular.isDefined(content) ? new RegExp(escapeRegexp(content)) : undefined; | ||
| var exception; | ||
|
|
||
| if (!angular.isFunction(actual)) { | ||
| throw new Error('Actual is not a function'); | ||
| @@ -298,41 +344,17 @@ beforeEach(function() { | ||
| exception = e; | ||
| } | ||
|
|
||
| if (exception) { | ||
| exceptionMessage = exception.message || exception; | ||
| } | ||
|
|
||
| var 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) { | ||
| if (isNot) { | ||
| return { pass: !result, message: message }; | ||
| } else { | ||
| return { pass: result, message: message }; | ||
| } | ||
| } | ||
| var matcher = new MinErrMatcher(isNot, namespace, code, content, { | ||
| inputType: 'function', | ||
| expectedAction: 'throw', | ||
| actualAction: 'threw' | ||
| }); | ||
|
|
||
| if (angular.isDefined(regex)) { | ||
| if (isNot) { | ||
| return { pass: !regex.test(exceptionMessage), message: message }; | ||
| } else { | ||
| return { pass: regex.test(exceptionMessage), message: message }; | ||
| } | ||
| } | ||
| if (isNot) { | ||
| return { pass: !result, message: message }; | ||
| } else { | ||
| return { pass: result, message: message }; | ||
| } | ||
| return matcher.test(exception); | ||
| }; | ||
| } | ||
| }, | ||
|
|
||
| toBeMarkedAsSelected: function() { | ||
| // Selected is special because the element property and attribute reflect each other's state. | ||
| // IE9 will wrongly report hasAttribute('selected') === true when the property is | ||
| @@ -1712,7 +1712,7 @@ describe('jqLite', function() { | ||
| aElem.on('click', noop); | ||
| expect(function() { | ||
| aElem.off('click', noop, '.test'); | ||
| }).toThrowError(/\[jqLite:offargs\]/); | ||
| }).toThrowMinErr('jqLite', 'offargs'); | ||
| }); | ||
| }); | ||
|
|
||
| @@ -1862,8 +1862,8 @@ describe('$compile', function() { | ||
| $httpBackend.flush(); | ||
|
|
||
| expect(sortedHtml(element)).toBe('<div><b class="hello"></b></div>'); | ||
| expect($exceptionHandler.errors[0].message).toMatch( | ||
| /^\[\$compile:tpload] Failed to load template: hello\.html/); | ||
| expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'tpload', | ||
| 'Failed to load template: hello.html'); | ||
| }) | ||
| ); | ||
|
|
||
| @@ -1885,9 +1885,9 @@ describe('$compile', function() { | ||
| $compile('<div><div class="sync async"></div></div>'); | ||
| $httpBackend.flush(); | ||
|
|
||
| expect($exceptionHandler.errors[0].message).toMatch(new RegExp( | ||
| '^\\[\\$compile:multidir] Multiple directives \\[async, sync] asking for ' + | ||
| 'template on: <div class="sync async">')); | ||
| expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir', | ||
| 'Multiple directives [async, sync] asking for template on: ' + | ||
| '<div class="sync async">'); | ||
| }); | ||
| }); | ||
|
|
||
| @@ -2096,15 +2096,17 @@ describe('$compile', function() { | ||
| $templateCache.put('template.html', 'dada'); | ||
| $compile('<p template></p>'); | ||
| $rootScope.$digest(); | ||
| expect($exceptionHandler.errors.pop().message). | ||
| toMatch(/\[\$compile:tplrt\] Template for directive 'template' must have exactly one root element\. template\.html/); | ||
| expect($exceptionHandler.errors.pop()).toEqualMinErr('$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). | ||
| toMatch(/\[\$compile:tplrt\] Template for directive 'template' must have exactly one root element\. template\.html/); | ||
| expect($exceptionHandler.errors.pop()).toEqualMinErr('$compile', 'tplrt', | ||
| 'Template for directive \'template\' must have exactly one root element. ' + | ||
| 'template.html'); | ||
|
|
||
| // ws is ok | ||
| $templateCache.put('template.html', ' <div></div> \n'); | ||
| @@ -2676,9 +2678,9 @@ describe('$compile', function() { | ||
| compile('<div class="tiscope-a; scope-b"></div>'); | ||
| $httpBackend.flush(); | ||
|
|
||
| expect($exceptionHandler.errors[0].message).toMatch(new RegExp( | ||
| '^\\[\\$compile:multidir] Multiple directives \\[scopeB, tiscopeA] ' + | ||
| 'asking for new/isolated scope on: <div class="tiscope-a; scope-b ng-scope">')); | ||
| expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir', | ||
| 'Multiple directives [scopeB, tiscopeA] asking for new/isolated scope on: ' + | ||
| '<div class="tiscope-a; scope-b ng-scope">'); | ||
| }) | ||
| ); | ||
|
|
||
| @@ -4628,7 +4630,8 @@ describe('$compile', function() { | ||
| // Update val to trigger the unstable onChanges, which will result in an error | ||
| $rootScope.$apply('a = 42'); | ||
| expect($exceptionHandler.errors.length).toEqual(1); | ||
| expect($exceptionHandler.errors[0].toString()).toContain('[$compile:infchng] 10 $onChanges() iterations reached.'); | ||
| expect($exceptionHandler.errors[0]). | ||
| toEqualMinErr('$compile', 'infchng', '10 $onChanges() iterations reached.'); | ||
| }); | ||
| }); | ||
|
|
||
| @@ -8821,16 +8824,19 @@ describe('$compile', function() { | ||
|
|
||
| it('should throw on an ng-transclude element inside no transclusion directive', function() { | ||
| inject(function($rootScope, $compile) { | ||
| // we need to do this because different browsers print empty attributes differently | ||
| var error; | ||
|
|
||
| try { | ||
| $compile('<div><div ng-transclude></div></div>')($rootScope); | ||
| } catch (e) { | ||
| expect(e.message).toMatch(new RegExp( | ||
| '^\\[ngTransclude:orphan\\] ' + | ||
| 'Illegal use of ngTransclude directive in the template! ' + | ||
| 'No parent directive that requires a transclusion found\\. ' + | ||
| 'Element: <div ng-transclude.+')); | ||
| error = e; | ||
| } | ||
|
|
||
| expect(error).toEqualMinErr('ngTransclude', 'orphan', | ||
| 'Illegal use of ngTransclude directive in the template! ' + | ||
| 'No parent directive that requires a transclusion found. ' + | ||
| 'Element: <div ng-transclude'); | ||
| // we need to do this because different browsers print empty attributes differently | ||
| }); | ||
| }); | ||
|
|
||
| @@ -8898,10 +8904,10 @@ describe('$compile', function() { | ||
| $rootScope.$digest(); | ||
|
|
||
| expect($exceptionHandler.errors[0][1]).toBe('<div class="bar" ng-transclude="">'); | ||
| expect($exceptionHandler.errors[0][0].message).toMatch(new RegExp( | ||
| '^\\[ngTransclude:orphan] Illegal use of ngTransclude directive in the ' + | ||
| 'template! No parent directive that requires a transclusion found. Element: ' + | ||
| '<div class="bar" ng-transclude="">')); | ||
| expect($exceptionHandler.errors[0][0]).toEqualMinErr('ngTransclude', 'orphan', | ||
| 'Illegal use of ngTransclude directive in the template! ' + | ||
| 'No parent directive that requires a transclusion found. ' + | ||
| 'Element: <div class="bar" ng-transclude="">'); | ||
| }); | ||
| }); | ||
|
|
||
| @@ -9717,9 +9723,8 @@ describe('$compile', function() { | ||
| $compile('<div template first></div>'); | ||
| $httpBackend.flush(); | ||
|
|
||
| expect($exceptionHandler.errors[0].message).toMatch(new RegExp( | ||
| '^\\[\\$compile:multidir] Multiple directives \\[first, second] asking for ' + | ||
| 'transclusion on: <p ')); | ||
| expect($exceptionHandler.errors[0]).toEqualMinErr('$compile', 'multidir', | ||
| 'Multiple directives [first, second] asking for transclusion on: <p '); | ||
| }); | ||
| }); | ||
|
|
||
Oops, something went wrong.