angular
.module('app', []);
// Tests here
describe('Angular stack trace truncated in Chrome', function () {
it('throws', function () {
angular.mock.module('app', function ($provide) {
throw 'This error should show up'
});
angular.mock.inject();
expect(true).toBe(true);
});
});
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<title>AngularJS test</title>
<script src="stack-reporter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.1.0/jasmine.js"></script>
<script src="jasmine-boot.js"></script>
<script src="https://code.angularjs.org/1.5.11/angular.js"></script>
<script src="https://code.angularjs.org/1.5.11/angular-mocks.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="app.js"></script>
<script src="appSpec.js"></script>
</head>
<body>
<pre id="reporter" style="border: 1px solid black; min-height: 200px; background: lightgrey; padding: 5px; white-space: pre-wrap;"></pre>
</body>
</html>
/* restore "body" styling that were changes by "jasmine.css"... */
body { background-color: white; padding: 0; margin: 8px; }
/* ... but remain the "jasmine.css" styling for the Jasmine reporting */
.jasmine_reporter { background-color: #eeeeee; padding: 0; margin: 0; }
cf https://github.com/jasmine/jasmine/issues/1378
(function() {
/**
* ## Require & Instantiate
*
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
*/
window.jasmine = jasmineRequire.core(jasmineRequire);
/**
* Create the Jasmine environment. This is used to run all specs in a project.
*/
var env = jasmine.getEnv();
/**
* ## The Global Interface
*
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
*/
var jasmineInterface = jasmineRequire.interface(jasmine, env);
/**
* Add all of the Jasmine global/public interface to the global scope, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
*/
extend(window, jasmineInterface);
// Custom reporter
env.addReporter(StackReporter);
/**
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
*/
window.setTimeout = window.setTimeout;
window.setInterval = window.setInterval;
window.clearTimeout = window.clearTimeout;
window.clearInterval = window.clearInterval;
/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
env.execute();
};
/**
* Helper function for readability above.
*/
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}
}());
(function () {
var StackReporter = {
specDone: function (result) {
var e = result.failedExpectations[0];
StackReporter.sendToReport(
"Stack (excludes all but line 1): \n\n" + e.stack + "\n\n\n" +
"Message (includes entire exception): \n\n" + e.message
);
},
sendToReport: function (obj) {
document.getElementById('reporter').innerHTML = obj.toString();
}
}
window.StackReporter = StackReporter;
})();