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 1.4.x branch (issue #13594) #13597

Open
wants to merge 7 commits into
base: v1.4.x
Choose a base branch
from
Open
Next Next commit
refactor(ngMock window.inject test): create room for planned tests
Split up `ngMock` `window.inject` tests into tests on browsers supporting
fetching current stack trace information and those not supporting it, as
we plan on adding new test specs to the first group.

Required making the test inject caller function more flexible so it can be
easily configured in different tests without unnecessary code duplication.
  • Loading branch information
jurko-gospodnetic committed Apr 11, 2016
commit bb752d1b701b38dd2635af2db5a977fbf77ffe2c
75 changes: 46 additions & 29 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,50 +920,67 @@ describe('ngMock', function() {
}).toThrow('test message');
}));

describe('error stack trace when called outside of spec context', function() {
// - Chrome, Firefox, Edge, Opera give us the stack trace as soon as an Error is created
// - IE10+, PhantomJS give us the stack trace only once the error is thrown
// - IE9 does not provide stack traces
var stackTraceSupported = (function() {
var error = new Error();
if (!error.stack) {
try {
throw error;
} catch (e) {}
}
// - Chrome, Firefox, Edge, Opera give us the stack trace as soon as an Error is created
// - IE10+, PhantomJS give us the stack trace only once the error is thrown
// - IE9 does not provide stack traces
var stackTraceSupported = (function() {
var error = new Error();
if (!error.stack) {
try {
throw error;
} catch (e) {}
}

return !!error.stack;
})();
return !!error.stack;
})();

function testCaller() {
function testInjectCaller() {
var shouldThrow;
var injectingCall = (function internalInjectCaller() {
return inject(function() {
throw new Error();
if (shouldThrow)
throw new Error();
});
}
var throwErrorFromInjectCallback = testCaller();
})();
injectingCall.setThrow = function(value) {
shouldThrow = value;
};
return injectingCall;
}

if (stackTraceSupported) {
describe('on browsers supporting stack traces', function() {
it('should update thrown Error stack trace with inject call location', function() {
if (!stackTraceSupported) {
describe('on browsers not supporting stack traces', function() {
describe('when called outside of test spec context', function() {
var injectingCall = testInjectCaller();

it('should not add stack trace information to thrown injection Error', function() {
injectingCall.setThrow(true);
try {
throwErrorFromInjectCallback();
injectingCall();
} catch (e) {
expect(e.stack).toMatch('testCaller');
expect(e.stack).toBeUndefined();
}
});
});
} else {
describe('on browsers not supporting stack traces', function() {
it('should not add stack trace information to thrown Error', function() {
});
}

if (stackTraceSupported) {
describe('on browsers supporting stack traces', function() {
describe('when called outside of test spec context and initial inject callback invocation fails', function() {
var throwingInjectingCall = testInjectCaller();
throwingInjectingCall.setThrow(true);

it('should update thrown Error stack trace with inject call location', function() {
try {
throwErrorFromInjectCallback();
throwingInjectingCall();
} catch (e) {
expect(e.stack).toBeUndefined();
expect(e.stack).toMatch('testInjectCaller');
}
});
});
}
});
});
}
});
});

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy