angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Component generation without spec file?

Open duncanhunter opened this issue 10 years ago • 13 comments

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?

duncanhunter avatar Jun 30 '16 19:06 duncanhunter

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.

kylecordes avatar Jun 30 '16 20:06 kylecordes

Maybe an api like:

ng g c new-component --nospec

jschwarty avatar Jul 28 '16 20:07 jschwarty

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

ng g c testfile --spec false

estrellajm avatar Nov 19 '17 11:11 estrellajm

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 } } }

Ranjita-M avatar May 15 '18 07:05 Ranjita-M

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

hayat12 avatar May 17 '18 02:05 hayat12

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

amitarora1991 avatar Jul 01 '18 07:07 amitarora1991

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.

agupadilla avatar Feb 27 '19 16:02 agupadilla

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

aledroner avatar Mar 01 '19 19:03 aledroner

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
  }
}

Yash-777 avatar Apr 03 '19 09:04 Yash-777

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 avatar Apr 30 '19 15:04 mmmichl

@mmmichl Working Solution!

life347 avatar May 09 '19 10:05 life347

ng generate directive "directiveName" --skipTests

ahadGitHub avatar Jul 16 '19 14:07 ahadGitHub

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.