From b8ea7f6aba2e675b85826b0bee1f21ddd7b866a5 Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Fri, 24 May 2013 11:00:14 -0700
Subject: feat(ngError): add error message compression and better error
messages
- add toThrowNg matcher
---
test/ng/animatorSpec.js | 2 +-
test/ng/cacheFactorySpec.js | 2 +-
test/ng/compileSpec.js | 41 ++++++++++++++++++++++++++++-----------
test/ng/controllerSpec.js | 10 ++++++++++
test/ng/directive/inputSpec.js | 14 ++++++-------
test/ng/directive/ngRepeatSpec.js | 14 ++++++-------
test/ng/directive/selectSpec.js | 4 ++--
test/ng/interpolateSpec.js | 4 ++--
test/ng/locationSpec.js | 8 ++++----
test/ng/parseSpec.js | 10 +++++-----
test/ng/rootScopeSpec.js | 12 ++++++------
11 files changed, 75 insertions(+), 46 deletions(-)
(limited to 'test/ng')
diff --git a/test/ng/animatorSpec.js b/test/ng/animatorSpec.js
index d4d7c0ec..cf5667d2 100644
--- a/test/ng/animatorSpec.js
+++ b/test/ng/animatorSpec.js
@@ -719,6 +719,6 @@ describe("$animator", function() {
expect(function() {
var animate = $animator($rootScope, { ngAnimate: ':' });
animate.enter();
- }).toThrow("Syntax Error: Token ':' not a primary expression at column 1 of the expression [:] starting at [:].");
+ }).toThrow("[NgErr24] 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 ddfadbbc..4b15fd7b 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('cacheId cache1 taken');
+ toThrow("[NgErr10] CacheId 'cache1' is already taken!");
}));
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 26f61357..bf3d0b77 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('Template must have exactly one root element. was: dada');
+ }).toThrow("[NgErr12] Template for directive 'noRootElem' must have exactly one root element.");
expect(function() {
$compile('');
- }).toThrow('Template must have exactly one root element. was: ');
+ }).toThrow("[NgErr12] 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('Failed to load template: hello.html');
+ }).toThrow('[NgErr17] Failed to load template: hello.html');
expect(sortedHtml(element)).toBe('
')($rootScope);
+ }).toThrow("[NgErr13] Controller 'main', required by directive 'dep', can't be found!");
+ });
+ });
+
+
it('should have optional controller on current element', function() {
module(function() {
directive('dep', function(log) {
@@ -2415,7 +2434,7 @@ describe('$compile', function() {
inject(function($compile) {
expect(function() {
$compile('');
- }).toThrow('Multiple directives [first, second] asking for transclusion on: ' +
+ }).toThrow('[NgErr18] Multiple directives [first, second] asking for transclusion on: ' +
'
');
});
});
diff --git a/test/ng/controllerSpec.js b/test/ng/controllerSpec.js
index f0dcb407..b041dec7 100644
--- a/test/ng/controllerSpec.js
+++ b/test/ng/controllerSpec.js
@@ -124,5 +124,15 @@ describe('$controller', function() {
expect(scope.foo).toBe(foo);
expect(scope.foo.mark).toBe('foo');
});
+
+
+ it('should throw an error if $scope is not provided', function() {
+ $controllerProvider.register('a.b.FooCtrl', function() { this.mark = 'foo'; });
+
+ expect(function() {
+ $controller('a.b.FooCtrl as foo');
+ }).toThrow("[NgErr47] 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 f8898074..68caf1f5 100644
--- a/test/ng/directive/inputSpec.js
+++ b/test/ng/directive/inputSpec.js
@@ -43,7 +43,7 @@ describe('NgModelController', function() {
}
expect(exception.message).
- toMatch(/Non-assignable model expression: 1\+2 \(\)/);
+ toMatch(/^\[NgErr6\] ngModel error! Expression '1\+2' is non\-assignable\. Element: $/);
}));
@@ -457,7 +457,7 @@ describe('input', function() {
expect(function() {
compileInput('');
scope.$digest();
- }).toThrow("Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at [''].");
+ }).toThrow("[NgErr24] Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at [''].");
});
@@ -548,11 +548,11 @@ describe('input', function() {
});
- xit('should throw an error when scope pattern can\'t be found', function() {
- compileInput('');
-
- expect(function() { changeInputValueTo('xx'); }).
- toThrow('Expected fooRegexp to be a RegExp but was undefined');
+ it('should throw an error when scope pattern can\'t be found', function() {
+ expect(function() {
+ compileInput('');
+ scope.$apply();
+ }).toThrowNg('ngPattern error! Expected fooRegexp to be a RegExp but was undefined.');
});
});
diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js
index e7e9af35..ac6ceb83 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("Expected ngRepeat in form of '_item_ in _collection_[ track by _id_]' but got 'i dont parse'.");
+ toBe("[NgErr7] ngRepeat error! 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("'item' in 'item in collection' should be identifier or (key, value) but got 'i dont parse'.");
+ toBe("[NgErr8] ngRepeat error! '_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('Duplicates in a repeater are not allowed. Repeater: item in items key: object:003');
+ 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");
// recover
scope.items = [a];
@@ -501,7 +501,7 @@ describe('ngRepeat', function() {
scope.items = [d, d, d];
scope.$digest();
expect($exceptionHandler.errors.shift().message).
- toEqual('Duplicates in a repeater are not allowed. Repeater: item in items key: object:009');
+ 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");
// recover
scope.items = [a];
@@ -563,7 +563,7 @@ describe('ngRepeat ngAnimate', function() {
}
function applyCSS(element, cssProp, cssValue) {
- element.css(cssProp, cssValue);
+ element.css(cssProp, cssValue);
element.css(vendorPrefix + cssProp, cssValue);
}
@@ -592,7 +592,7 @@ describe('ngRepeat ngAnimate', function() {
'