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

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

问题描述

我使用 Angular-CLI(测试版 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快速入门的项目,我可以手动将规范添加到jasmine文件中.但我不知道如何在 karma 测试之外进行设置,或者如何将 karma 测试限制为使用 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天全站免登陆