angularangular-testangular-unit-testangular-testing-library

Angular Unit testing: How to pass multiple files through include while running ng test from CLI?


I am using ng test to run my unit tests.

I have a scenario where I need to test mutliple spec files which are in different paths.

I am able to do this using angular.json

"test": {
...
"include": ["**/test1.spec.ts","**/test2.spec.ts"],
..
}

I am able to run a single spec file using ng test --include=**/test1.spec.ts

But how to pass an array or multiple spec file path through ng test --include?

FYI: As per angular docs, ng test --include parameter is of type array.

    --include "**/test1.spec.ts,**/test2.spec.ts"
    --include="**/test1.spec.ts","**/test2.spec.ts"
    --include=["**/test1.spec.ts","**/test2.spec.ts"]
    --include=[**/test1.spec.ts,**/test2.spec.ts]

I tried all these possibilities but nothing seemed to help. Can someone help me understand how to pass multiple file path / array to --include through CLI.


Solution

  • I had the same issue.

    The Angular docs say the --include parameter is of type array, but the correct syntax isn't clear.

    You can specify the --include parameter multiple times, once for each file pattern:

    ng test --include **/test1.spec.ts --include **/test2.spec.ts