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

Commit

Permalink
fix(ngMocks): allow ErrorAddingDeclarationLocationStack to be recog…
Browse files Browse the repository at this point in the history
…nized 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
  • Loading branch information
peabnuts123 authored and gkalpak committed Jun 29, 2016
1 parent 7ce7e09 commit f7405e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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
21 changes: 19 additions & 2 deletions 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,22 @@ describe('ngMock', function() {
});
}
});

describe('ErrorAddingDeclarationLocationStack', function() {
it('should be caught by Jasmine\'s `toThrowError()`', function() {
function throwErrorAddingDeclarationStack() {
module(function($provide) {
$provide.factory('badFactory', function() {
throw new Error('BadFactoryError');
});
});

inject(function(badFactory) {});
}

expect(throwErrorAddingDeclarationStack).toThrowError(/BadFactoryError/);
});
});
});
});

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


describe('`afterEach` clean-up', function() {
describe('`$rootElement`', function() {

describe('undecorated', function() {
var prevRootElement;
var prevCleanDataSpy;
Expand Down Expand Up @@ -2780,6 +2797,7 @@ describe('`afterEach` clean-up', function() {
});
});


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

});

0 comments on commit f7405e3

Please sign in to comment.