Angular-cli: Component generation without spec file?

Created on 30 Jun 2016  路  13Comments  路  Source: angular/angular-cli

Frequently we make components with no logic that we do not wish to write unit tests for. We would like to use the CLI to generate components with no spec file.

  1. How do you use the generation feature of the CLI with out creating a spec file?
2 (required)

Most helpful comment

to generate a component without a "...spec.ts" file you simply run "--spec false". Example below

ng g c testfile --spec false

All 13 comments

I think this is especially relevant for projects that follow the "smart component vs visual component" pattern. The purely visual components in such a design usually should not have anything in them worthy of a test.

Maybe an api like:

ng g c new-component --nospec

to generate a component without a "...spec.ts" file you simply run "--spec false". Example below

ng g c testfile --spec false

Hi there!!
Look at the default settings of component in schema.json(node_modules/@angular/cli/lib/config/schema.json) file. Change as required..

If you don't want to generate spec file, just make default property value to false..
"component":
{
"properties":
{
"spec":
{
"description": "Specifies if a spec file is generated.",
"type": "boolean",
"default": true
}
}
}

Hello, @duncanhunter i am advancing you to create the component manually, mostly when we use cli we don't know what is the use of the generated files. and in case if you want to generate the component with cli without spec you can use this ng g component list --spec==false

you can use -S with command to skip the test files

to generate a component without a "...spec.ts" file you simply run "--spec false". Example below

ng g c testfile --spec false

Option "spec" is deprecated: Use "skipTests" instead.

Option "spec" is deprecated: Use "skipTests" instead. Example:
ng g s my-service --skipTests

application

ng generate application <name> [options]

| OPTION | DESCRIPTION |
| :-- | :-- |
| --skipTests=true\|false |When true, does not create "spec.ts" test files for the app.
Default: false
Aliases: -S |

component

ng generate component <name> [options]

| OPTION | DESCRIPTION |
| :-- | :-- |
| --skipTests=true\|false | When true, does not create "spec.ts" test files for the new component/directive/class/guard.
Default: false |
| --spec=true\|false | _Deprecated_: Use "skipTests" instead.
When true (the default), generates a "spec.ts" test file for the new component.
Default: true |


Angular 2:

ng g c component-name --spec false

angular-cli.json

"defaults": {
  "spec": {
    "class": false,
    "component": true,
    "directive": true,
    "module": false,
    "pipe": true,
    "service": true
  }
}

for consistency angular.json with angular cli 7:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  ...
  "projects": {
    "your-app": {
      ...
      "schematics": {
        "@schematics/angular:component": {
          "inlineStyle": false,
          "spec": false
        }
      },
....
}

@mmmichl Working Solution!

ng generate directive "directiveName" --skipTests

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings