Mharlin
Mharlin

Reputation: 1705

Stack trace for Jasmine test with the Resharper 7 test runner

How do you get the Resharper 7 test runner to show the stacktrace for Jasmine tests.

My setup is Resharper 7 (build in Jasmine) testrunner and PhantomJs. When executing any failing test the error message always ends with:

Exception doesn't have a stacktrace

In the 1.6 "Lavender" version of Phantom has added the feature to print the stacktrace when an error occurs.

To replicate this just create a mytest.js file and add the following code to it:

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(false);
  });
});

Upvotes: 3

Views: 2704

Answers (3)

Mharlin
Mharlin

Reputation: 1705

Got a good response from the Jetbrains Resharper team when I logged the issue. They fixed it and it's in the 7.1 release of Resharper, which can be downloaded from their EAP site

Upvotes: 3

pa3zo6
pa3zo6

Reputation: 71

Sorry, I don't use Resharper, but I used to face the same issue with phantomjs and jasmine ConsoleReporter.

I think it boils down to the fact that jasmine does not throw an Error message for failed expectations and that the stack is captured by phantomjs only when error is actually thrown (jasmine.js):

jasmine.ExpectationResult = function(params) {
...
var trace = (params.trace || new Error(this.message));
};

Changing that line as follows fixed it for me:

var err;
try { throw new Error(this.message); } catch(e) { err = e };
var trace = (params.trace || err);

Upvotes: 7

David De Sloovere
David De Sloovere

Reputation: 3435

In the spec file, where you have your javascript (jasmine) unit tests, you need a reference to the source that is being tested. Normally you have this in the SpecRunner.html, but Resharper rolls it's own SpecRunner.

Add this reference line to the top of the XyzSpec.js file

/// <reference path="/js/path-goes-here/your-file-here.js" />

describe("Utils", function () {
    describe("when calculating quantity", function() {
...

Drove me almost nuts until I started looking around in Resharper's spec runner.

PS: If a new problem shows up 'Unit Test Runner failed to load test assembly' and you have Chrome as default browser, change the browser for javascript unit tests in the Resharper options.

Upvotes: 5

Related Questions