How to execute only one test spec with angular-cli

前端 未结 10 731
执笔经年
执笔经年 2020-12-02 06:00

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

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

I used to have a project based on

10条回答
  •  抹茶落季
    2020-12-02 06:10

    This is working for me in Angular 7. It is based on the --main option of the ng command. I am not sure if this option is undocumented and possibly subject to change, but it works for me. I put a line in my package.json file in scripts section. There using the --main option of with the ng test command, I specify the path to the .spec.ts file I want to execute. For example

    "test 1": "ng test --main E:/WebRxAngularClient/src/app/test/shared/my-date-utils.spec.ts",
    

    You can run the script as you run any such script. I run it in Webstorm by clicking on "test 1" in the npm section.

提交回复
热议问题