【问题标题】:What should I use instead of fit and fdescribe in Jasmine 3?我应该在 Jasmine 3 中使用什么来代替 fit 和 fdescribe?
【发布时间】:2018-05-28 07:23:10
【问题描述】:

我得到错误:

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

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

【问题讨论】:

  • 那些功能仍然存在,消息告诉你,如果所有的重点测试都通过了,那么整个运行现在将是不完整的,不会通过。
  • 谢谢。他们应该将其记录为 WARN。
  • 我认为在这种情况下错误更准确。如果您忘记从规范中删除 fit 或 fdescribe,我希望我的 CI 失败!
  • FWIW,我同意@heldt,deprecation 通常意味着另一种选择。如果实际上没有任何东西被破坏并且没有替代方案存在,那么我们应该怎么做?
  • 这仍然是个问题吗?看起来它已经在这里解决了:github.com/karma-runner/karma-jasmine/issues/202 并且可能在这里相关:github.com/jasmine/jasmine/issues/1532

标签: angular testing jasmine karma-runner


【解决方案1】:

根据您指向fit docs的链接

fit 将专注于一个或一组测试。

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

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

ERROR --> WARNING: 告诉你只有 fit'S 会运行,因此是一个不完整测试。

谢谢。

【讨论】:

  • 是的,但是当它说 deprecation 之类的内容时,我更喜欢以 最新 而不是某些已弃用的方式运行测试句法。 OP 遇到的问题(就像我们一样)是,似乎没有替代品可供依赖而不是弃用的东西。
  • 据我了解,您应该只在创建新测试的情况下使用fit,这样您就不需要等待其他人检查它。然后将其设置回it 以运行它们。
  • 这实际上是个好主意。但是,就问题而言,我们仍然会收到弃用警告,并且让我感到困扰的是我没有最新的替代方案可以更改。
  • 这在添加 karma-chai 和东西时尤其麻烦... fit 或 fdescribe 使整个事情停止工作,包括我们试图关注的那些
【解决方案2】:

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

所以我们仍然可以使用 fit 和 fdescribe ,请阅读下面的代码,它是 cmets 。它经过测试且易于理解。

//If you want to run few describe only add f so using focus those describe blocks and it's it block get run

  fdescribe("focus description i get run with all my it blocks ", function() {
    it("1 it in fdescribe get executed", function() {
        console.log("1 it in fdescribe get executed unless no fit within describe");

    });
    it("2 it in fdescribe get executed", function() {
        console.log("2 it in fdescribe get executed unless no fit within describe");

    });
    //but if you and fit in fdescribe block only the fit blocks get executed
    fit("3  only fit blocks in  fdescribe get executed", function() {
        console.log("If there is  a fit   in fdescribe only fit blocks  get executed");

    });
  });

  describe("none description i get skipped with all my it blocks ", function() {
        it("1 it in none describe get skipped", function() {
            console.log("1 it in none describe get skipped");

        });
        it("2 it in none describe get skipped", function() {
            console.log("2 it in none describe get skipped");
        });
//What happen if we had fit in a none fdescribe block will it get run ?   yes  
       fit("3 fit in none describe get executed too eventhough it;s just describe ", function() {
            console.log("3 fit in none describe get executed too");
        }); 
      });

【讨论】:

    猜你喜欢
    • 2015-09-27
    • 1970-01-01
    • 2010-11-05
    • 2010-12-06
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多