From d804bbcd51ec83bee1f4a3ccd42c3bd7eb38a988 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 19 Jul 2012 14:07:00 -0700 Subject: 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. --- test/ng/interpolateSpec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/ng/interpolateSpec.js') 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('
{{1 + 1}}
{{err()}}
{{1 + 2}}
'); + $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'; -- cgit v1.2.3