在Jasmine 3中我应该使用什么而不是合适和fdescribe?

hel*_*ldt 42 testing jasmine karma-runner angular

我收到错误:

ERROR: 'DEPRECATION: fit and fdescribe will cause your suite to report an 'incomplete' status in Jasmine 3.0'
Run Code Online (Sandbox Code Playgroud)

我为Jasmine 3.0做了一个RTFM,但没有提到任何关于弃用的内容:https://jasmine.github.io/api/3.0/global.html#fit

T04*_*435 8

根据您适合文档的链接

fit 将重点放在一个或一组测试上。

因此,如果您有5个测试3 it和2 fit,那么只有2个适合的测试将由Jasmine进行。

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

ERROR --> WARNING:告诉您只会运行fit'S,因此测试不完整

谢谢。

  • 这实际上是一个好主意。但是,就这个问题而言,我们仍然会收到过时警告,这让我感到困扰,因为我没有最新的替代方法。 (7认同)
  • 是的,但是当它显示诸如* deprecation *之类的内容时,我更喜欢以*最新*的方式而不是某些不推荐使用的语法来运行测试。OP的问题(就像我们一样)是,似乎没有替代品可供使用,而不是不推荐使用的替代品。 (3认同)
  • 根据我的理解,您应该只在创建新测试的情况下使用“fit”,这样您就无需等待其他人检查它。然后将其设置回 `it` 以运行它们。 (3认同)

Sam*_*lva 4

他们已经修正了警告。我正在使用 jasmine v3.3.1,但没有看到这样的消息:

控制台输出显示下面示例代码的 jasmine 测试运行。 仅执行“fdescribe”定义中的“fit”块以及常规“describe”定义中的“fit”块。

所以我们仍然可以使用fitand fdescribe,请阅读下面的代码及其注释。它经过测试并且易于理解。

// 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");
  });
});
Run Code Online (Sandbox Code Playgroud)