新しいコンポーネントを作成するたびに、Angular 2+ で spec.ts ファイルを削除する方法はありますか? これはテスト目的であることはわかっていますが、必要ない場合はどうでしょうか。
この特定のテスト ファイルを無効にする設定がある可能性があります。
新しいコンポーネントを作成するたびに、Angular 2+ で spec.ts ファイルを削除する方法はありますか? これはテスト目的であることはわかっていますが、必要ない場合はどうでしょうか。
この特定のテスト ファイルを無効にする設定がある可能性があります。
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
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
}
}
これを試してみてください。これは機能しています
ng g c component_name --spec false
Angular 8 の場合:ng generate component mycomponent --skipTests=false
修正 #156によれば、spec ファイルなしでコンポーネントを作成できます。
ng generate component my-comp --nospec
それは私のために働いています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