From b499958e0ca7798833de9031434f1ebd1661d803 Mon Sep 17 00:00:00 2001 From: Jeff Andrews Date: Wed, 30 Mar 2016 22:57:04 +1300 Subject: [PATCH 1/3] fix(ngMock): Change ErrorAddingDeclarationLocationStack prototype change prototype to Error.prototype so test frameworks can catch it properly #13821 --- src/ngMock/angular-mocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 3b4f94a211ec..e8fdfae489d9 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -2774,7 +2774,7 @@ if (window.jasmine || window.mocha) { this.stack = e.stack + '\n' + errorForStack.stack; if (e.stackArray) this.stackArray = e.stackArray; }; - ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString; + ErrorAddingDeclarationLocationStack.prototype = Error.prototype; window.inject = angular.mock.inject = function() { var blockFns = Array.prototype.slice.call(arguments, 0); From a6f9f2630b2b8313b5668b7dd8edf4a13b125b86 Mon Sep 17 00:00:00 2001 From: Jeff Andrews Date: Thu, 31 Mar 2016 01:19:54 +1300 Subject: [PATCH 2/3] test(ngMock): adding test adding test to verify change --- test/ngMock/angular-mocksSpec.js | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 1dc2c36b8104..0beed42a3c12 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -2505,6 +2505,44 @@ describe('`afterEach` clean-up', function() { }); }); + describe('ErrorAddingDeclarationLocationStack', function() { + it('should be caught by jasmine\'s toThrowError', function() { + //create function that causes an error + function causeNgMocksError() { + module(function($provide) { + //cause $provide.factory to include an error + $provide.factory('causeError', function() { + //Say for example, some mock module caused an error when instantiated + throw new Error("Error!"); + }); + }); + + //call the injector on 'causeError' to make sure the provider is called + var causeError; + inject(function(_causeError_) { + causeError = _causeError_; + }); + } + + //The following is a simplified implementation of future Jasmine's .toThrowError() + // which is at the root of this problem + var error; + try { + causeNgMocksError(); + } catch (e) { + error = e; + } + + //Apologies for inelegant pass/fail conditions + if (error instanceof Error) { + //pass test + expect(true).toBe(true); + } else { + //fail test + throw new Error("Expected Error but got " + error); + } + }); + }); describe('uninstantiated or falsy `$rootElement`', function() { it('should not break if `$rootElement` was never instantiated', function() { From 4d86f4fd361ad8f8f8e880ff64d345e85fad377a Mon Sep 17 00:00:00 2001 From: Jeff Andrews Date: Thu, 31 Mar 2016 01:39:35 +1300 Subject: [PATCH 3/3] test(ngMock): style changes removed trailing whitespace, fixed 4-space tab, changed to 2 spaces --- test/ngMock/angular-mocksSpec.js | 68 ++++++++++++++++---------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 0beed42a3c12..c3257454aaf2 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -2507,40 +2507,40 @@ describe('`afterEach` clean-up', function() { describe('ErrorAddingDeclarationLocationStack', function() { it('should be caught by jasmine\'s toThrowError', function() { - //create function that causes an error - function causeNgMocksError() { - module(function($provide) { - //cause $provide.factory to include an error - $provide.factory('causeError', function() { - //Say for example, some mock module caused an error when instantiated - throw new Error("Error!"); - }); - }); - - //call the injector on 'causeError' to make sure the provider is called - var causeError; - inject(function(_causeError_) { - causeError = _causeError_; - }); - } - - //The following is a simplified implementation of future Jasmine's .toThrowError() - // which is at the root of this problem - var error; - try { - causeNgMocksError(); - } catch (e) { - error = e; - } - - //Apologies for inelegant pass/fail conditions - if (error instanceof Error) { - //pass test - expect(true).toBe(true); - } else { - //fail test - throw new Error("Expected Error but got " + error); - } + //create function that causes an error + function causeNgMocksError() { + module(function($provide) { + //cause $provide.factory to include an error + $provide.factory('causeError', function() { + //Say for example, some mock module caused an error when instantiated + throw new Error("Error!"); + }); + }); + + //call the injector on 'causeError' to make sure the provider is called + var causeError; + inject(function(_causeError_) { + causeError = _causeError_; + }); + } + + //The following is a simplified implementation of future Jasmine's .toThrowError() + // which is at the root of this problem + var error; + try { + causeNgMocksError(); + } catch (e) { + error = e; + } + + //Apologies for inelegant pass/fail conditions + if (error instanceof Error) { + //pass test + expect(true).toBe(true); + } else { + //fail test + throw new Error("Expected Error but got " + error); + } }); });