0

I have below spec, in the afterEach, I defined a variable to verify the spec result status, and want to do something according it. After execute the the expected false spec, I found the variable didnot return the correct result.

describe('test suite', function() {
  afterEach(function (done) {
    var failedStatus = (this.status == 'failed');
    //do sth with the variable failedStatus
    console.log(failedStatus);
  });

  it('should be a failed', function() {
    expect(false).toBe(true);
  });
});

In above, I expect the failedStatus should be True, but it return False. How to correct it? Thank you.

Boyka Zhu
  • 391
  • 1
  • 4
  • 18
  • Have you defined a variable called `status` somewhere and using it `this.status`? Can you show that implementation? Thanks – giri-sh Mar 31 '16 at 08:30
  • @GirishSortur , I didnot defined it. Does "this" has the status property could automatically verify the spec result status? – Boyka Zhu Mar 31 '16 at 08:41
  • 1
    `this` always refers to current context that you calling it in, in your case it refers to your function. In order to get correct spec result check this - http://jasmine.github.io/edge/custom_reporter.html. Hope it helps. – giri-sh Mar 31 '16 at 08:56
  • @GirishSortur very thanks for the tips. it works for me. – Boyka Zhu Apr 01 '16 at 02:38

1 Answers1

1

Solution - in your base configuration you should add custom reporter and call specDone which collects the data of this specific spec.

jasmine.getEnv().addReporter({
        specDone:function (result) {
            console.log("spec name:"+ result.fullName);
            console.log("result:"+ result.status);
            console.log("id:"+ result.id);
            console.log("description:"+ result.description);
        }
    });

according to documentation,The capabilities are:

interface CustomReporterResult {
    description: string;
    failedExpectations?: FailedExpectation[];
    fullName: string;
    id: string;
    passedExpectations?: PassedExpectation[];
    pendingReason?: string;
    status?: string;
}

For more info you can read the full documentation: link

avivamg
  • 12,197
  • 3
  • 67
  • 61