Skip to content

Commit 7b089fe

Browse files
test(ngMock window.inject): test extending inject error stack info
Angular's ngMock inject() function, when called outside of a test spec context will not directly call the provided callback but will instead return a wrapper function to call the provided function at a later time, presumably while in some test spec context. And if that is the case, Angular would like to include the information on the inject() calling location to be included in the thrown error's stack trace information, so it manually appends it to the ones included in the actual error's stack trace. The added test makes sure this functionality works as expected. Closes angular#13591
1 parent a57286c commit 7b089fe

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/ngMock/angular-mocksSpec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,23 @@ describe('ngMock', function() {
919919
});
920920
}).toThrow('test message');
921921
}));
922+
923+
describe('when called outside of test spec context and inject callback throws an Error', function () {
924+
function testCaller() {
925+
return inject(function () {
926+
throw new Error();
927+
});
928+
}
929+
var throwErrorFromInjectCallback = testCaller();
930+
931+
it('should update thrown Error stack with inject call location', function () {
932+
try {
933+
throwErrorFromInjectCallback();
934+
} catch (e) {
935+
expect(e.stack).toMatch('testCaller');
936+
}
937+
});
938+
});
922939
});
923940
});
924941

0 commit comments

Comments
 (0)