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

Commit c6074dc

Browse files
peabnuts123gkalpak
authored andcommitted
fix(ngMocks): allow ErrorAddingDeclarationLocationStack to be recognized as an Error
Change `ErrorAddingDeclarationLocationStack`'s prototype so test frameworks (such as Jasmine 2.x) are able to recognize it as `Error`. Fixes #13821 Closes #14344
1 parent 4930ef2 commit c6074dc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/ngMock/angular-mocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,7 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) {
30333033
this.stack = e.stack + '\n' + errorForStack.stack;
30343034
if (e.stackArray) this.stackArray = e.stackArray;
30353035
};
3036-
ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString;
3036+
ErrorAddingDeclarationLocationStack.prototype = Error.prototype;
30373037

30383038
window.inject = angular.mock.inject = function() {
30393039
var blockFns = Array.prototype.slice.call(arguments, 0);

test/ngMock/angular-mocksSpec.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ describe('ngMock', function() {
631631

632632
inject(); // Trigger the tests in `module`
633633
});
634-
635634
});
636635

637636

@@ -985,6 +984,22 @@ describe('ngMock', function() {
985984
});
986985
}
987986
});
987+
988+
describe('ErrorAddingDeclarationLocationStack', function() {
989+
it('should be caught by Jasmine\'s `toThrowError()`', function() {
990+
function throwErrorAddingDeclarationStack() {
991+
module(function($provide) {
992+
$provide.factory('badFactory', function() {
993+
throw new Error('BadFactoryError');
994+
});
995+
});
996+
997+
inject(function(badFactory) {});
998+
}
999+
1000+
expect(throwErrorAddingDeclarationStack).toThrowError(/BadFactoryError/);
1001+
});
1002+
});
9881003
});
9891004
});
9901005

@@ -2525,8 +2540,10 @@ describe('make sure that we can create an injector outside of tests', function()
25252540
angular.injector([function($injector) {}]);
25262541
});
25272542

2543+
25282544
describe('`afterEach` clean-up', function() {
25292545
describe('`$rootElement`', function() {
2546+
25302547
describe('undecorated', function() {
25312548
var prevRootElement;
25322549
var prevCleanDataSpy;
@@ -2689,6 +2706,7 @@ describe('`afterEach` clean-up', function() {
26892706
});
26902707
});
26912708

2709+
26922710
describe('sharedInjector', function() {
26932711
// this is of a bit tricky feature to test as we hit angular's own testing
26942712
// mechanisms (e.g around jQuery cache checking), as ngMock augments the very
@@ -2946,5 +2964,4 @@ describe('sharedInjector', function() {
29462964
if (typeof fn !== "function") throw Error("not fn", fn);
29472965
sdescribe.current.afterEach.push(fn);
29482966
}
2949-
29502967
});

0 commit comments

Comments
 (0)