From ba10d178b251db5e3e44630999c7c8463135ac12 Mon Sep 17 00:00:00 2001 From: "Davis W. Frank" Date: Wed, 1 Jun 2011 21:14:59 -0700 Subject: [PATCH] Better stack trace on exception. Better results if exception is due to true exception --- lib/jasmine.js | 36 +++++++++++++++++++++++------------- src/Spec.js | 3 ++- src/base.js | 31 ++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/lib/jasmine.js b/lib/jasmine.js index ec7ad44..e2e265c 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -80,7 +80,7 @@ jasmine.MessageResult = function(values) { jasmine.MessageResult.prototype.toString = function() { var text = ""; - for(var i = 0; i < this.values.length; i++) { + for (var i = 0; i < this.values.length; i++) { if (i > 0) text += " "; if (jasmine.isString_(this.values[i])) { text += this.values[i]; @@ -97,9 +97,10 @@ jasmine.ExpectationResult = function(params) { this.passed_ = params.passed; this.expected = params.expected; this.actual = params.actual; - this.message = this.passed_ ? 'Passed.' : params.message; - this.trace = this.passed_ ? '' : new Error(this.message); + + var trace = params.trace || new Error(this.message); + this.trace = this.passed_ ? '' : trace; }; jasmine.ExpectationResult.prototype.toString = function () { @@ -125,7 +126,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return jasmine.isA_("Array", value); + return jasmine.isA_("Array", value); }; /** @@ -593,17 +594,25 @@ jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { try { return f(); } catch(e) { - } + } return null; } - - var xhr = tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.6.0");}) || - tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");}) || - tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP");}) || - tryIt(function(){return new ActiveXObject("Microsoft.XMLHTTP");}); + + var xhr = tryIt(function() { + return new ActiveXObject("Msxml2.XMLHTTP.6.0"); + }) || + tryIt(function() { + return new ActiveXObject("Msxml2.XMLHTTP.3.0"); + }) || + tryIt(function() { + return new ActiveXObject("Msxml2.XMLHTTP"); + }) || + tryIt(function() { + return new ActiveXObject("Microsoft.XMLHTTP"); + }); if (!xhr) throw new Error("This browser does not support XMLHttpRequest."); - + return xhr; } : XMLHttpRequest; /** @@ -1999,7 +2008,8 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag jasmine.Spec.prototype.fail = function (e) { var expectationResult = new jasmine.ExpectationResult({ passed: false, - message: e ? jasmine.util.formatException(e) : 'Exception' + message: e ? jasmine.util.formatException(e) : 'Exception', + trace: { stack: e.stack } }); this.results_.addResult(expectationResult); }; @@ -2458,5 +2468,5 @@ jasmine.version_= { "major": 1, "minor": 1, "build": 0, - "revision": 1306336386 + "revision": 1306942160 }; diff --git a/src/Spec.js b/src/Spec.js index b24f859..972ccfd 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -120,7 +120,8 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag jasmine.Spec.prototype.fail = function (e) { var expectationResult = new jasmine.ExpectationResult({ passed: false, - message: e ? jasmine.util.formatException(e) : 'Exception' + message: e ? jasmine.util.formatException(e) : 'Exception', + trace: { stack: e.stack } }); this.results_.addResult(expectationResult); }; diff --git a/src/base.js b/src/base.js index cd7e778..bb0c555 100755 --- a/src/base.js +++ b/src/base.js @@ -80,7 +80,7 @@ jasmine.MessageResult = function(values) { jasmine.MessageResult.prototype.toString = function() { var text = ""; - for(var i = 0; i < this.values.length; i++) { + for (var i = 0; i < this.values.length; i++) { if (i > 0) text += " "; if (jasmine.isString_(this.values[i])) { text += this.values[i]; @@ -97,9 +97,10 @@ jasmine.ExpectationResult = function(params) { this.passed_ = params.passed; this.expected = params.expected; this.actual = params.actual; - this.message = this.passed_ ? 'Passed.' : params.message; - this.trace = this.passed_ ? '' : new Error(this.message); + + var trace = (params.trace || new Error(this.message)); + this.trace = this.passed_ ? '' : trace; }; jasmine.ExpectationResult.prototype.toString = function () { @@ -125,7 +126,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return jasmine.isA_("Array", value); + return jasmine.isA_("Array", value); }; /** @@ -593,16 +594,24 @@ jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { try { return f(); } catch(e) { - } + } return null; } - - var xhr = tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.6.0");}) || - tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP.3.0");}) || - tryIt(function(){return new ActiveXObject("Msxml2.XMLHTTP");}) || - tryIt(function(){return new ActiveXObject("Microsoft.XMLHTTP");}); + + var xhr = tryIt(function() { + return new ActiveXObject("Msxml2.XMLHTTP.6.0"); + }) || + tryIt(function() { + return new ActiveXObject("Msxml2.XMLHTTP.3.0"); + }) || + tryIt(function() { + return new ActiveXObject("Msxml2.XMLHTTP"); + }) || + tryIt(function() { + return new ActiveXObject("Microsoft.XMLHTTP"); + }); if (!xhr) throw new Error("This browser does not support XMLHttpRequest."); - + return xhr; } : XMLHttpRequest;