angularangular-cliangular-builder

ng test not passing Jest CLI options any more in v14?


I am using Jest with Angular (instead of Karma). The angular.json file seems to be configured properly, as running ng test works.

According to this article:

You can specify Jest CLI options either in builder options (useful when it is a persistent config) or right to ng test as a parameter (useful when it is a one-timer).

For example to run a single test:

ng test --testNamePattern="My test suite My test case"

This was working before my v14 upgrade, but this is not the case any more. Now if I run:

ng test --testNamePattern="MyComponent"

I get:

Error: Unknown argument: testNamePattern
Angular CLI: 14.0.2
Node: 16.13.1
Package Manager: yarn 1.22.17 
OS: darwin arm64

Angular: 14.0.2
... animations, cdk, cli, common, compiler, compiler-cli, core
... elements, forms, language-service, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1400.2
@angular-devkit/build-angular   14.0.2
@angular-devkit/core            14.0.2
@angular-devkit/schematics      8.3.29
@schematics/angular             14.0.2
rxjs                            6.6.7
typescript                      4.7.4

Note: this is possibly a regression of the builder


Solution

  • Okay quoting @just-jeb from github

    It's mentioned in the migration guide. It's a breaking change of Angular CLI, not the builder. camelCase arguments are no longer supported.

    Here is therefore the proper way to run the "MyComponent" test

    ng test --test-name-pattern="MyComponent"
    

    Note: Jetbrains does not yet (28.06.2022) supports the kebab case arguments