Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngMock): Change ErrorAddingDeclarationLocationStack prototype #14344

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3057,7 +3057,7 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) {
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);
Expand Down
22 changes: 21 additions & 1 deletion test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ describe('ngMock', function() {

inject(); // Trigger the tests in `module`
});

});


Expand Down Expand Up @@ -985,6 +984,27 @@ describe('ngMock', function() {
});
}
});

it('Errors 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_;
});
}

expect(causeNgMocksError).toThrowError(/Error/g);
});
});
});

Expand Down