Permalink
Browse files

Fix for missing traces on test failure if using Phantom.js

  • Loading branch information...
1 parent 74cdc5a commit ed6fb0740f8105a4fc188e9e567855aecd7703d6 @jphpsf committed Oct 30, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/jasmine-core/jasmine.js
View
4 lib/jasmine-core/jasmine.js
@@ -106,7 +106,9 @@ jasmine.ExpectationResult = function(params) {
this.actual = params.actual;
this.message = this.passed_ ? 'Passed.' : params.message;
- var trace = (params.trace || new Error(this.message));
+ var err;
+ try { throw new Error(this.message); } catch(e) { err = e };
@r4j4h
r4j4h Nov 15, 2012

I think the ending semicolon is a little off, I think it should be
try { throw new Error(this.message); } catch(e) { err = e; }

+ var trace = (params.trace || err);
this.trace = this.passed_ ? '' : trace;
};

2 comments on commit ed6fb07

@JamesMGreene

Adding comment directly to the commit to ensure it is seen merging.
I'd love to see this fixed, too, but I would probably advise rewriting this so that it doesn't throw an Error unnecessarily (not always a light hit) if the tests passed in the first place. For example:

this.trace = this.passed_ ? '' : (function() {
    var trace = params.trace;
    if (!trace) {
        try {
            throw new Error(this.message);
        }
        catch(e) {
            trace = e;
        }
    }
    return trace;
})();
@jphpsf
Owner

Thanks for your comment. I will look into it soon and improve the patch.

Please sign in to comment.