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

Fix ngMock window.inject() stack trace reporting on PhanthomJS for 1.4.x branch #13592

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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 in browsers supporting JavaScript stack trace
  collection, e.g. Chrome, Firefox, IE10+, Opera & PhantomJS
- does not add any bogus stack track information in browsers that do
  not support JavaScript stack trace collection, e.g. IE8 or IE9

Closes #13591
  • Loading branch information
jurko-gospodnetic committed Apr 8, 2016
commit 6c45811b32068b7b28377fa90ad66bf0ce8bff8f
47 changes: 47 additions & 0 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,53 @@ describe('ngMock', function() {
});
}).toThrow('test message');
}));

describe('when called outside of test spec context and inject callback throws an Error', function() {
// - IE9 does not support providing stack traces
// - Chrome & Firefox give us the stack trace as soon as an Error is
// created
// - IE10, IE11 & PhantomJS give us the stack trace only once the error
// is thrown
var stackTraceSupported = (function() {
var error = new Error();
if (error.stack)
return error.stack;
try {
throw error;
} catch (e) {
return e.stack;
}
})();

function testCaller() {
return inject(function() {
throw new Error();
});
}
var throwErrorFromInjectCallback = testCaller();

if (stackTraceSupported) {
describe('on browsers supporting stack traces', function() {
it('should update thrown Error stack with inject call location', function() {
try {
throwErrorFromInjectCallback();
} catch (e) {
expect(e.stack).toMatch('testCaller');
}
});
});
} else {
describe('on browsers not supporting stack traces', function() {
it('should not add stack trace information to thrown Error', function() {
try {
throwErrorFromInjectCallback();
} catch (e) {
expect(e.stack).not.toBeDefined();
}
});
});
}
});
});
});

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