In recent Angular versions you can configure the cli generator to disable the creation of spec file for components and services in angular-cli.json as follows:
Just adding this bit of information because I found myself struggling with the same issue and could not fix it by using the current answer(s), plus I did not want to make the changes on the angular-cli.json file. It appears the recent version of Angular CLI --spec=false is depreciated and therefore no longer works, use --skipTests instead.
Test on:
Angular CLI: 9.1.1
Node: 12.16.1
OS: win32 x64
Your command with then be:
ng g c mycomponent --skipTests
instead of
ng g c mycomponent --spec=false
PS: Always test your commands using the --dry-run option to test your output.
ng generate component your-component-name --skipTests=true
or using the alias s instead of --skipTests
ng generate component your-component-name -s=true
Modifying angular.json to avoid using above CLI command always
Copy the below snippet to the root of a specific project (projects.your-project-name) in its angular.json.
The below will ensure .spec files are not created for Components, Class, Directives, Pipe and Service with the ng generate command. You may choose the ones as per requirement.
You have to use "--skip-tests true" when generating component.
(Note: you can get the above version info by trying "ng v" or "ng -v" in the terminal).
You can get the complete list of switches for "ng g c (short for ng generate component)" using "ng g c --help".
Alternatively you can add a component manually. To do this, make a new folder by right clicking the /src/app folder of your project. After creating the folder, right click on it to add one or more files such as mycomp.component.html and mycomp.component.ts.
Adding mycomp.component.ts is the minimum required list for a component, as you can add inline css and html to your .ts file.
Import and Register MyComp in app.module.ts declarations list, and add it to app.component.html or some other template, using selector (<app-mycomp></app-mycomp>