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

16,106

Solution 1

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");
  });
});

Solution 2

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.

Share:
16,106

Related videos on Youtube

heldt
Author by

heldt

No info for you!

Updated on June 12, 2022

Comments

  • heldt
    heldt almost 2 years

    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

    • jonrsharpe
      jonrsharpe almost 6 years
      Those functions will still be there, the message is telling you that the overall run will now be incomplete, not passed, if all the focused tests pass.
    • heldt
      heldt almost 6 years
      Thanks. They should have logged it as a WARN instead.
    • Jonas Stawski
      Jonas Stawski over 5 years
      I think an error is more accurate in this case. If you forget to remove fit or fdescribe from your specs I want my CI to fail!
    • Eric Liprandi
      Eric Liprandi over 5 years
      FWIW, I agree with @heldt, deprecation usually implies an alternative. If nothing is actually broken and no alternative exists, then what are we supposed to do?
    • Konrad Viltersten
      Konrad Viltersten about 5 years
      @EricLiprandi Did you ever find out the answer? We're sitting with exactly the same issue now and I even put bounty on it. Really worrying with such a wall of silence on such a straightforward question.
    • Eric Liprandi
      Eric Liprandi about 5 years
      @KonradViltersten sorry, I have not... I am pretty sure we're still on 2.x... I will look into this in the coming weeks.
    • Boris Yakubchik
      Boris Yakubchik about 5 years
      Is this still an issue? It looks like it had been resolved here: github.com/karma-runner/karma-jasmine/issues/202 and maybe related here: github.com/jasmine/jasmine/issues/1532
  • Konrad Viltersten
    Konrad Viltersten about 5 years
    Yeah but when it says stuff like deprecation, I prefer to run the tests in a way that's up-to-date and not some deprecated syntax. The problem OP has (as do we), is that there seems to be no alternatives offered to rely on instead of the deprecated stuff.
  • T04435
    T04435 about 5 years
    For my understanding, you should only use fit in the case you creating a new test so you don't need to wait for the others to check it. Then set it back to it to run them all.
  • Konrad Viltersten
    Konrad Viltersten about 5 years
    That's actually a good idea. However, as far the question is concerned, we'd still get the deprecation warning, and it bothers me that I have no up-to-daty alternatives to change to.
  • RoboticRenaissance
    RoboticRenaissance over 3 years
    This is especially bothersome when adding karma-chai and stuff in... fit or fdescribe make the entire thing stop working, including the ones we're trying to focus on
  • Alan Macdonald
    Alan Macdonald about 2 years
    This answer seems to explain what fit does whereas the question is about deprecation