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

Commit f7405e3

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 7ce7e09 commit f7405e3

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
@@ -3057,7 +3057,7 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) {
30573057
this.stack = e.stack + '\n' + errorForStack.stack;
30583058
if (e.stackArray) this.stackArray = e.stackArray;
30593059
};
3060-
ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString;
3060+
ErrorAddingDeclarationLocationStack.prototype = Error.prototype;
30613061

30623062
window.inject = angular.mock.inject = function() {
30633063
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

@@ -2616,8 +2631,10 @@ describe('make sure that we can create an injector outside of tests', function()
26162631
angular.injector([function($injector) {}]);
26172632
});
26182633

2634+
26192635
describe('`afterEach` clean-up', function() {
26202636
describe('`$rootElement`', function() {
2637+
26212638
describe('undecorated', function() {
26222639
var prevRootElement;
26232640
var prevCleanDataSpy;
@@ -2780,6 +2797,7 @@ describe('`afterEach` clean-up', function() {
27802797
});
27812798
});
27822799

2800+
27832801
describe('sharedInjector', function() {
27842802
// this is of a bit tricky feature to test as we hit angular's own testing
27852803
// mechanisms (e.g around jQuery cache checking), as ngMock augments the very
@@ -3037,5 +3055,4 @@ describe('sharedInjector', function() {
30373055
if (typeof fn !== "function") throw Error("not fn", fn);
30383056
sdescribe.current.afterEach.push(fn);
30393057
}
3040-
30413058
});

0 commit comments

Comments
 (0)