I got this work when executed directly through jasmine when the command is run jasmine ./tests/alLErrorException.spec.js. The following changes are required:
Always tune your listeners, even if _callbackyou shouldn't.
constructor(callback, startListening = true) {
if (!callback) {
throw new Error("Missing callback function");
}
this._callback = callback;
this._listening = startListening;
this._setupEvents();
}
Add a function to intercept events uncaughtExceptionand call _callbackif we _listening:
_handler() {
if(this._listening) {
this._callback.apply(null, arguments);
}
}
uncaughtException _setupEvents:
_setupEvents(attatch = true) {
this._listening = attatch ? true : false;
if (attatch) {
if (typeof window !== "undefined") {
window.addEventListener("error", this._callback);
} else {
// Added this line
process.removeAllListeners('uncaughtException');
process.addListener('uncaughtException', this._handler.bind(this));
}
} else {
if (typeof window !== "undefined") {
window.removeEventListener("error", this._callback);
} else {
process.removeListener('uncaughtException', this._callback);
}
}
}
, uncaughtException , AllErrorHandler.
- AllErrorHandler .