99

新しいコンポーネントを作成するたびに、Angular 2+ で spec.ts ファイルを削除する方法はありますか? これはテスト目的であることはわかっていますが、必要ない場合はどうでしょうか。

この特定のテスト ファイルを無効にする設定がある可能性があります。

4

29 に答える 29

222

Angular >=8 CLI 用に更新

1 つのコンポーネントに対して、次のコマンドを使用します。

ng generate component --skip-tests=true component-name

単一のプロジェクトの場合、次の内容を変更または追加しますangular.json

{ 
  "projects": {
    "{PROJECT_NAME}": {
      "schematics": {
        "@schematics/angular:component": {
          "skipTests": true
        }
      }
    }
  }
}

すべてのプロジェクトのグローバル設定については、次の内容を変更または追加してくださいangular.json

{ 
  "schematics": {
    "@schematics/angular:component": {
      "skipTests": true
    }
  }
}

またはコマンドラインを使用して

ng config schematics.@schematics/angular:component.skipTests true

<角度8

内部angular-cli.jsonで spec.component パラメータを次のように設定しますfalse

{
   ...
   "defaults" : {
       ...
       "spec": {
           ...
           "component": false
       }
   }
}

または--spec=false作成時にオプションを使用します

ng generate component --spec=false component-name
于 2016-12-06T07:57:22.017 に答える
10

angular-cli を使用する場合、渡すオプションがたくさんあります。--spec=falseテストなしで新しいコンポーネントを生成するには、次のように追加するだけです。

ng generate component --spec=false my-component

angular-cli.json には、デフォルトで仕様を有効にするタイプのオプションもあり、動作を変更できます。

"defaults": {
  "spec": {
    "class": false,
    "component": true,
    "directive": true,
    "module": false,
    "pipe": true,
    "service": true
  }
}
于 2016-12-06T07:57:51.813 に答える
4

これを試してみてください。これは機能しています

ng g c component_name --spec false
于 2018-05-02T14:10:54.917 に答える
3

Angular 8 の場合:ng generate component mycomponent --skipTests=false

于 2019-03-26T15:00:20.533 に答える
1

修正 #156によれば、spec ファイルなしでコンポーネントを作成できます。

ng generate component my-comp --nospec
于 2016-12-06T07:58:14.817 に答える
0

それは私のために働いていますangular 11

ng g c posts/new-component --module app --skip-tests

ノート:

コンポーネントの名前は次のようにする必要があります :new-componentまたはnewComponent.

特定のフォルダーに対して生成する:dir/new-component

new-componentに追加app.module.ts:--module app

ファイル--skip-testsなしでコンポーネントを生成するためのコマンドでjust を使用spec.ts

于 2021-04-10T09:21:00.567 に答える