aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/interpolateSpec.js
diff options
context:
space:
mode:
authorBrian Ford2012-07-19 14:07:00 -0700
committerIgor Minar2012-08-30 14:50:22 -0700
commitd804bbcd51ec83bee1f4a3ccd42c3bd7eb38a988 (patch)
treeb72cd4cf0bbe954da001ebe420d18bf77948ffdf /test/ng/interpolateSpec.js
parentd3fa7a2e9e93c9dae13d852b28c878f7d6b7c420 (diff)
downloadangular.js-d804bbcd51ec83bee1f4a3ccd42c3bd7eb38a988.tar.bz2
feat($interpolate): provide contextual error messages
if an exception occurs during interpolation of a string (e.g. name() in "Hello, {{name()}}!" throws an exception) we now print an error message with the expression that was being evaluated when the exception was thrown.
Diffstat (limited to 'test/ng/interpolateSpec.js')
-rw-r--r--test/ng/interpolateSpec.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/ng/interpolateSpec.js b/test/ng/interpolateSpec.js
index 20214445..a0a3e311 100644
--- a/test/ng/interpolateSpec.js
+++ b/test/ng/interpolateSpec.js
@@ -25,6 +25,29 @@ describe('$interpolate', function() {
expect($interpolate('{{ false }}')()).toEqual('false');
}));
+ it('should rethrow exceptions', inject(function($interpolate, $rootScope) {
+ $rootScope.err = function () {
+ throw new Error('oops');
+ };
+ expect(function () {
+ $interpolate('{{err()}}')($rootScope);
+ }).toThrow('Error while interpolating: {{err()}}\nError: oops');
+ }));
+
+ it('should stop interpolation when encountering an exception', inject(function($interpolate, $compile, $rootScope) {
+ $rootScope.err = function () {
+ throw new Error('oops');
+ };
+ var dom = jqLite('<div>{{1 + 1}}</div><div>{{err()}}</div><div>{{1 + 2}}</div>');
+ $compile(dom)($rootScope);
+ expect(function () {
+ $rootScope.$apply();
+ }).toThrow('Error while interpolating: {{err()}}\nError: oops');
+ expect(dom[0].innerHTML).toEqual('2');
+ expect(dom[1].innerHTML).toEqual('{{err()}}');
+ expect(dom[2].innerHTML).toEqual('{{1 + 2}}');
+ }));
+
it('should return interpolation function', inject(function($interpolate, $rootScope) {
$rootScope.name = 'Misko';