Skip to content

Component generation without spec file? #1256

Closed

Description

@duncanhunter

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?

Activity

  1. kylecordes commented on Jun 30, 2016

    @kylecordes

    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.

  2. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on Jul 4, 2016
  3. jschwarty commented on Jul 28, 2016

    @jschwarty
    Contributor

    Maybe an api like:

    ng g c new-component --nospec

  4. self-assigned this
    on Jul 28, 2016
  5. added 2 commits that reference this issue on Jul 28, 2016
    bb3fd55
    a85a507
  6. added a commit that references this issue on Jul 31, 2016
    fbdbedb
  7. estrellajm commented on Nov 19, 2017

    @estrellajm
    Contributor

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

    ng g c testfile --spec false

  8. Ranjita-M commented on May 15, 2018

    @Ranjita-M

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

  9. hayat12 commented on May 17, 2018

    @hayat12

    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

  10. amitarora1991 commented on Jul 1, 2018

    @amitarora1991

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

  11. agupadilla commented on Feb 27, 2019

    @agupadilla

    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.

  12. aledroner commented on Mar 1, 2019

    @aledroner

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

  13. Yash-777 commented on Apr 3, 2019

    @Yash-777

    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
      }
    }
  14. mmmichl commented on Apr 30, 2019

    @mmmichl

    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
            }
          },
    ....
    }
  15. life347 commented on May 9, 2019

    @life347

    @mmmichl Working Solution!

  16. ahadGitHub commented on Jul 16, 2019

    @ahadGitHub

    ng generate directive "directiveName" --skipTests

  17. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  18. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions