diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/BinderSpec.js | 2 | ||||
| -rw-r--r-- | test/ng/interpolateSpec.js | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/test/BinderSpec.js b/test/BinderSpec.js index 6d5dd91e..ba90539f 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()).toBe('MyError'); + expect(errorLogs.shift().message).toBe('Error while interpolating: {{error.throw()}}\nMyError'); $rootScope.error['throw'] = function() {return 'ok';}; $rootScope.$apply(); 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'; |
