如何使用 angular-cli 只执行一个测试规范 [英] How to execute only one test spec with angular-cli

查看:17
本文介绍了如何使用 angular-cli 只执行一个测试规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用 Angular-CLI(beta 20)构建的 Angular2 项目.

I have Angular2 project build with Angular-CLI (beta 20).

有没有办法只针对一个选定的规范文件运行测试?

Is there a way to run tests against only one selected spec file?

我曾经有一个基于Angular2快速入门的项目,我可以手动将specs添加到jasmine文件中.但我不知道如何在业力测试之外进行设置,或者如何将业力测试限制在使用 Angular-CLI 构建的特定文件中.

I used to have a project based on Angular2 quick start, and I could manually add specs to jasmine file. But I don't know how to set this up outside of karma testing or how to limit karma tests to specific files with Angular-CLI builds.

推荐答案

您的每个 .spec.ts 文件都将其所有测试分组在 describe 块中,如下所示:

Each of your .spec.ts file have all its tests grouped in describe block like this:

describe('SomeComponent', () => {...}

您可以通过在 describe 函数名称前加上 f 来轻松运行这个单个块:

You can easily run just this single block, by prefixing the describe function name with f:

fdescribe('SomeComponent', () => {...}

如果您有这样的功能,则不会运行其他 describe 块.顺便提一句.你可以用 it => fit 做类似的事情,还有一个黑名单"版本 - x.所以:

If you have such function, no other describe blocks will run. Btw. you can do similar thing with it => fit and there is also a "blacklist" version - x. So:

  • fdescribefit 导致 以这种方式标记的函数运行
  • xdescribexit 导致 所有但 标记为这种方式的函数运行
  • fdescribe and fit causes only functions marked this way to run
  • xdescribe and xit causes all but functions marked this way to run

这篇关于如何使用 angular-cli 只执行一个测试规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆