heldt
heldt

Reputation: 4266

What should I use instead of fit and fdescribe in Jasmine 3?

I get the error:

ERROR: 'DEPRECATION: fit and fdescribe will cause your suite to report an 'incomplete' status in Jasmine 3.0'

I did a RTFM for Jasmine 3.0 but it did not mention anything about deprecation: https://jasmine.github.io/api/3.0/global.html#fit

Upvotes: 47

Views: 23249

Answers (2)

Sameera De Silva
Sameera De Silva

Reputation: 1980

They have fixed the warning. I am using jasmine v3.3.1 and I don't see such a message:

Console output showing the jasmine test run for the sample code below. Only the 'fit' block in the 'fdescribe' definition as well as the 'fit' block in the regular 'describe' definition got executed.

So we can still use fit and fdescribe, please read the below code and its comments. It's tested and easy to understand.

// If you want to run a few describes only, add 'f' so using focus only those
// 'fdescribe' blocks and their 'it' blocks get run
fdescribe("Focus description: I get run with all my it blocks", function () {
  it("1) it in fdescribe gets executed", function () {
    console.log("1) gets executed unless there's a fit within fdescribe");
  });

  it("2) it in fdescribe gets executed", function () {
    console.log("2) gets executed unless there's a fit within fdescribe");
  });

  // But if you add 'fit' in an 'fdescribe' block, only the 'fit' block gets run
  fit("3) only fit blocks in fdescribe get executed", function () {
    console.log("If there's a fit in fdescribe, only fit blocks get executed");
  });
});

describe("Regular description: I get skipped with all my it blocks", function () {
  it("1) it in regular describe gets skipped", function () {
    console.log("1) gets skipped");
  });

  it("2) it in regular describe gets skipped", function () {
    console.log("2) gets skipped");
  });

  // Will a 'fit' in a regular describe block get run? Yes!
  fit("3) fit in regular describe still gets executed", function () {
    console.log("3) fit in regular describe gets executed, too");
  });
});

Upvotes: 4

T04435
T04435

Reputation: 13992

As per your link to fit docs

fit will focus on a test or a set of them.

so if you have 5 tests, 3it and 2fit, only the 2 with fit will run by Jasmine.

ERROR: 'DEPRECATION: fit and fdescribe will cause your suite to report an 'incomplete' status in Jasmine 3.0'

ERROR --> WARNING: Is telling you that only fit'S will run, therefore an incomplete test.

Thanks.

Upvotes: 14

Related Questions