【问题标题】:Angular 2 CLI, Can I test only certain SPEC, instead of all of them?Angular 2 CLI,我可以只测试某些 SPEC,而不是全部吗?
【发布时间】:2017-10-08 13:04:51
【问题描述】:

我在我的 web 项目中使用 angular 2 CLI,并且我编写了很多单元测试,随着我的代码库越来越大,测试变得越来越重。我想知道是否可以只测试我指定的 spec 文件的某些部分?

【问题讨论】:

    标签: angular unit-testing angular-cli


    【解决方案1】:

    test.ts文件

    // Then we find all the tests.
    const context = require.context('./', true, /\.spec\.ts$/);
    

    如果我只想测试我可以写的管道:

    const context = require.context('./', true, /pipe\.spec\.ts$/);
    

    【讨论】:

      【解决方案2】:

      您可以使用以下语法手动关闭测试或只运行特定测试。

      如果您在“描述”块前加上 f,则只会运行:

      fdescribe()
      

      如果你在“it”块前面加上一个 f,那么只有那个会运行:

      fit()
      

      您还可以使用“x”作为前缀以不运行块: xit() 和 xdescribe()

      见:How to execute only one test spec with angular-cli

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-08
        • 1970-01-01
        • 1970-01-01
        • 2019-01-02
        • 1970-01-01
        • 2020-03-30
        • 2013-05-04
        • 2019-08-06
        相关资源
        最近更新 更多