ngMock window.inject() does not add inject() call location info to errors thrown from repeated inject() callback calls #13594
Description
Overview of the Issue
ngMock
window.inject()
function has some seemingly quick-fix functionality adding the window.inject()
call location stack trace information to any errors thrown by the callback passed to the window.inject()
call. This however has a bug in that it only adds this information to errors thrown from the first callback invocation, but not for any later ones, while there are typical scenarios when a callback given to it may be invoked multiple times during a single test run.
Motivation for or Use Case
Here's a typical scenario where a callback passed to ngMock
's window.inject()
function gets called multiple times in a single test suite:
describe('I\'m a little tea pot', function() {
beforeEach(inject(function() {
throw new Error();
}));
it('first test spec', function () {});
it('second test spec', function () {});
});
Here the first test spec's error information will include the window.inject()
call location stack trace information, while the second test spec's will not. And if for some reason only the second test spec throws an error, then no window.inject()
call location stack trace information will be reported back to the user at all.
Angular Version(s)
- reproduced using angular
1.4.8
&master
versions
Browsers and Operating System
- reproducible using any browser supporting JavaScript error stack information, e.g. Chrome, Firefox & Opera, IE10+ & PhantomJS
- reproduced using
Ubuntu 15.10
, but should not be OS specific
Reproduce the Error
Just run the use case presented in the Motivation for or Use Case section above.
Suggest a Fix
- don't clear the
errorForStack
information after the first call to thewindow.inject()
callback