8000 Fix ngMock window.inject() error stack trace reporting on repeated or non-initial injection function calls for the master branch (issue #13594) by jurko-gospodnetic · Pull Request #13598 · angular/angular.js · GitHub
[go: up one dir, main page]

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

Fix ngMock window.inject() error stack trace reporting on repeated or non-initial injection function calls for the master branch (issue #13594) #13598

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
test(ngMock window.inject): error stack trace on inject with multiple…
… 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 #13594.
  • Loading branch information
jurko-gospodnetic committed Apr 11, 2016
commit 3a09c6daebebf050ce08d81538f6d87f5f482380
49 changes: 37 additions & 12 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,19 +932,28 @@ describe('ngMock', function() {
// function returned by inject(), when called outside of test spec
// context, may have stored state so do not reuse the result from this
// call in multiple test specs
function testInjectCaller() {
var shouldThrow;
// using an extra internalInjectCaller() wrapper here avoids stack trace
// constructed by some browsers (e.g. FireFox) from containing the name
// of the external caller function
var injectingCall = (function internalInjectCaller() {
return inject(function() {
if (shouldThrow)
function testInjectCaller(injectionFunctionCount) {
var shouldThrow = [];
// using an extra named function wrapper around the Error throw avoids
// stack trace constructed by some browsers (e.g. FireFox) from
// containing the name of the external caller function
function injectionFunction(index) {
return function() {
if (shouldThrow[index])
throw new Error();
});
})();
injectingCall.setThrow = function(value) {
shouldThrow = value;
};
}
var injectionFunctions = [];
for (var i = 0; i < (injectionFunctionCount || 1); ++i) {
injectionFunctions.push(injectionFunction(i));
}
var injectingCall = inject.apply(window, injectionFunctions);
injectingCall.setThrow = function(index, value) {
if (!isDefined(value)) {
value = index;
index = 0;
}
shouldThrow[index] = value;
};
return injectingCall;
}
Expand Down Expand Up @@ -1003,6 +1012,22 @@ describe('ngMock', function() {
}
});
});

describe('when called outside of test spec context with multiple injected functions', function() {
var injectingCall = testInjectCaller(2);

// regression test for issue #13594
// regression test for issue #13591 when run on IE10+ or PhantomJS
it('should update thrown Error stack when second injected function fails', function() {
injectingCall.setThrow(0, false);
injectingCall.setThrow(1, true);
try {
injectingCall();
} catch (e) {
expect(e.stack).toMatch('testInjectCaller');
}
});
});
});
}
});
Expand Down
0