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

ngMock window.inject() does not add inject() call location info to errors thrown from repeated inject() callback calls #13594

Open
jurko-gospodnetic opened this issue Dec 20, 2015 · 6 comments

Comments

@jurko-gospodnetic
Copy link
Contributor

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 the window.inject() callback
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Dec 20, 2015
…vocations

Failed injection functions should consistently include their respective
window.inject() call location information in their stack trace, even on
repeated invocations & when they have been passed as a non-initial
parameter to their window.inject() call.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Dec 20, 2015
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Dec 20, 2015
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
@jurko-gospodnetic
Copy link
Contributor Author

Pull request #13597 is a fix for this issue for the 1.4.x branch.
Pull request #13598 is a fix for this issue for the master branch.

jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Dec 20, 2015
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Dec 20, 2015
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
@jurko-gospodnetic
Copy link
Contributor Author

ping?

@Narretz Narretz added this to the Backlog milestone Jan 5, 2016
@Narretz
Copy link
Contributor

Narretz commented Jan 5, 2016

Thanks for raising this issue. It's not super high priority, so we'll look into it when we have the time.

@jurko-gospodnetic
Copy link
Contributor Author

Heh, yeah... but clear pull requests #13597 & #13598 have been prepared resolving it so I don't think officially fixing this issue should take much time. And most of the changes in the pull requests are just added tests for previously completely untested part of the code-base. 😄

Kind of a low hanging fruit at the moment while, as the time goes by, the pull requests will just naturally collect conflicts.

There are actually two separate issues touching the same part of the code-base here - #13591 & this one - #13594. The pull requests for #13591 need to be applied first, as the pull requests for this issue build on those, adding to the same part of the test suite. And I think all the pull requests should be real easy to review + merge.:smile:

Please let me know if there is anything else I can do to get this merged.

Many thanks,
Jurko Gospodnetić

jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Apr 8, 2016
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Apr 8, 2016
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Apr 11, 2016
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Apr 11, 2016
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
jurko-gospodnetic added a commit to jurko-gospodnetic/angular.js that referenced this issue Apr 11, 2016
… functions

Injection function throwing an Error should update the thrown Error's
stack trace information with the window.inject() call location information
even when multiple injection functions are passed to the window.inject()
call and non-initial provided function fails.

Closes angular#13594.
@Narretz
Copy link
Contributor

Narretz commented Apr 11, 2016

Looks like the PRs have been merged!

@Narretz Narretz closed this as completed Apr 11, 2016
@Narretz
Copy link
Contributor

Narretz commented Apr 11, 2016

Oh no, the other one has been merged ...

@Narretz Narretz reopened this Apr 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants