What are the “spec.ts” files generated by Angular CLi for?
I'm new to Angular 2 (and Angular in general...) and am finding it very engaging. I am using Angular CLi to generate and serve projects. It seems to work well – though for my little learning projects, it produces more than I need – but that's to be expected.
I've noticed that it generates spec.ts for each Angular element in a project (Component, Service, Pipe, etc). I've searched around but have not found an explanation of what these files are for.
Are these build files which are normally hidden when using tsc? I wondered because I wanted to change the name of a poorly named Component I'd created and discovered that the name was also referenced in these spec.ts files.
import {
beforeEach,
beforeEachProviders,
describe,
expect,
it,
inject,
} from '@angular/core/testing';
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { PovLevelComponent } from './pov-level.component';
describe('Component: PovLevel', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [PovLevelComponent]);
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
builder = tcb;
}));
it('should inject the component', inject([PovLevelComponent],
(component: PovLevelComponent) => {
expect(component).toBeTruthy();
}));
it('should create the component', inject(, () => {
return builder.createAsync(PovLevelComponentTestController)
.then((fixture: ComponentFixture<any>) => {
let query = fixture.debugElement.query(By.directive(PovLevelComponent));
expect(query).toBeTruthy();
expect(query.componentInstance).toBeTruthy();
});
}));
});
@Component({
selector: 'test',
template: `
<app-pov-level></app-pov-level>
`,
directives: [PovLevelComponent]
})
class PovLevelComponentTestController {
}
angular typescript
add a comment |
I'm new to Angular 2 (and Angular in general...) and am finding it very engaging. I am using Angular CLi to generate and serve projects. It seems to work well – though for my little learning projects, it produces more than I need – but that's to be expected.
I've noticed that it generates spec.ts for each Angular element in a project (Component, Service, Pipe, etc). I've searched around but have not found an explanation of what these files are for.
Are these build files which are normally hidden when using tsc? I wondered because I wanted to change the name of a poorly named Component I'd created and discovered that the name was also referenced in these spec.ts files.
import {
beforeEach,
beforeEachProviders,
describe,
expect,
it,
inject,
} from '@angular/core/testing';
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { PovLevelComponent } from './pov-level.component';
describe('Component: PovLevel', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [PovLevelComponent]);
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
builder = tcb;
}));
it('should inject the component', inject([PovLevelComponent],
(component: PovLevelComponent) => {
expect(component).toBeTruthy();
}));
it('should create the component', inject(, () => {
return builder.createAsync(PovLevelComponentTestController)
.then((fixture: ComponentFixture<any>) => {
let query = fixture.debugElement.query(By.directive(PovLevelComponent));
expect(query).toBeTruthy();
expect(query.componentInstance).toBeTruthy();
});
}));
});
@Component({
selector: 'test',
template: `
<app-pov-level></app-pov-level>
`,
directives: [PovLevelComponent]
})
class PovLevelComponentTestController {
}
angular typescript
add a comment |
I'm new to Angular 2 (and Angular in general...) and am finding it very engaging. I am using Angular CLi to generate and serve projects. It seems to work well – though for my little learning projects, it produces more than I need – but that's to be expected.
I've noticed that it generates spec.ts for each Angular element in a project (Component, Service, Pipe, etc). I've searched around but have not found an explanation of what these files are for.
Are these build files which are normally hidden when using tsc? I wondered because I wanted to change the name of a poorly named Component I'd created and discovered that the name was also referenced in these spec.ts files.
import {
beforeEach,
beforeEachProviders,
describe,
expect,
it,
inject,
} from '@angular/core/testing';
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { PovLevelComponent } from './pov-level.component';
describe('Component: PovLevel', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [PovLevelComponent]);
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
builder = tcb;
}));
it('should inject the component', inject([PovLevelComponent],
(component: PovLevelComponent) => {
expect(component).toBeTruthy();
}));
it('should create the component', inject(, () => {
return builder.createAsync(PovLevelComponentTestController)
.then((fixture: ComponentFixture<any>) => {
let query = fixture.debugElement.query(By.directive(PovLevelComponent));
expect(query).toBeTruthy();
expect(query.componentInstance).toBeTruthy();
});
}));
});
@Component({
selector: 'test',
template: `
<app-pov-level></app-pov-level>
`,
directives: [PovLevelComponent]
})
class PovLevelComponentTestController {
}
angular typescript
I'm new to Angular 2 (and Angular in general...) and am finding it very engaging. I am using Angular CLi to generate and serve projects. It seems to work well – though for my little learning projects, it produces more than I need – but that's to be expected.
I've noticed that it generates spec.ts for each Angular element in a project (Component, Service, Pipe, etc). I've searched around but have not found an explanation of what these files are for.
Are these build files which are normally hidden when using tsc? I wondered because I wanted to change the name of a poorly named Component I'd created and discovered that the name was also referenced in these spec.ts files.
import {
beforeEach,
beforeEachProviders,
describe,
expect,
it,
inject,
} from '@angular/core/testing';
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { PovLevelComponent } from './pov-level.component';
describe('Component: PovLevel', () => {
let builder: TestComponentBuilder;
beforeEachProviders(() => [PovLevelComponent]);
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
builder = tcb;
}));
it('should inject the component', inject([PovLevelComponent],
(component: PovLevelComponent) => {
expect(component).toBeTruthy();
}));
it('should create the component', inject(, () => {
return builder.createAsync(PovLevelComponentTestController)
.then((fixture: ComponentFixture<any>) => {
let query = fixture.debugElement.query(By.directive(PovLevelComponent));
expect(query).toBeTruthy();
expect(query.componentInstance).toBeTruthy();
});
}));
});
@Component({
selector: 'test',
template: `
<app-pov-level></app-pov-level>
`,
directives: [PovLevelComponent]
})
class PovLevelComponentTestController {
}
angular typescript
angular typescript
edited Nov 24 '18 at 17:18
displayname
6,5261679165
6,5261679165
asked May 28 '16 at 19:01
No GrabbingNo Grabbing
9,3161258124
9,3161258124
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The spec files are unit tests for your source files. The convention for Angular applications is to have a .spec.ts file for each .ts file. They are run using the Jasmine javascript test framework through the Karma task runner when you use the ng test command.
You can use this for some further reading:
https://angular.io/guide/testing
9
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
3
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
11
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
21
when you generate an new component with CLI you can add--spec=falseto exclude the generation of a spec file. The full command for generating a new component would be:ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component
– Dean
May 31 '17 at 19:14
5
this can be disabled by modifyingangular-cli.jsonlike this:{ "defaults": { "component": { "spec": false } } }
– Ali Sherafat
Feb 19 '18 at 18:35
|
show 1 more comment
if you generate new angular project using "ng new", you may skip a generating of spec.ts files. For this you should apply --skip-tests option.
ng new ng-app-name --skip-tests
add a comment |
The .spec.ts files are for unit tests for individual components.
You can run Karma task runner through ng test. In order to see code coverage of unit test cases for particular components run ng test --code-coverage
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37502809%2fwhat-are-the-spec-ts-files-generated-by-angular-cli-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The spec files are unit tests for your source files. The convention for Angular applications is to have a .spec.ts file for each .ts file. They are run using the Jasmine javascript test framework through the Karma task runner when you use the ng test command.
You can use this for some further reading:
https://angular.io/guide/testing
9
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
3
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
11
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
21
when you generate an new component with CLI you can add--spec=falseto exclude the generation of a spec file. The full command for generating a new component would be:ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component
– Dean
May 31 '17 at 19:14
5
this can be disabled by modifyingangular-cli.jsonlike this:{ "defaults": { "component": { "spec": false } } }
– Ali Sherafat
Feb 19 '18 at 18:35
|
show 1 more comment
The spec files are unit tests for your source files. The convention for Angular applications is to have a .spec.ts file for each .ts file. They are run using the Jasmine javascript test framework through the Karma task runner when you use the ng test command.
You can use this for some further reading:
https://angular.io/guide/testing
9
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
3
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
11
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
21
when you generate an new component with CLI you can add--spec=falseto exclude the generation of a spec file. The full command for generating a new component would be:ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component
– Dean
May 31 '17 at 19:14
5
this can be disabled by modifyingangular-cli.jsonlike this:{ "defaults": { "component": { "spec": false } } }
– Ali Sherafat
Feb 19 '18 at 18:35
|
show 1 more comment
The spec files are unit tests for your source files. The convention for Angular applications is to have a .spec.ts file for each .ts file. They are run using the Jasmine javascript test framework through the Karma task runner when you use the ng test command.
You can use this for some further reading:
https://angular.io/guide/testing
The spec files are unit tests for your source files. The convention for Angular applications is to have a .spec.ts file for each .ts file. They are run using the Jasmine javascript test framework through the Karma task runner when you use the ng test command.
You can use this for some further reading:
https://angular.io/guide/testing
edited Sep 18 '18 at 9:58
Jan Papenbrock
7861819
7861819
answered May 28 '16 at 19:13
awisemanawiseman
3,07111315
3,07111315
9
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
3
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
11
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
21
when you generate an new component with CLI you can add--spec=falseto exclude the generation of a spec file. The full command for generating a new component would be:ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component
– Dean
May 31 '17 at 19:14
5
this can be disabled by modifyingangular-cli.jsonlike this:{ "defaults": { "component": { "spec": false } } }
– Ali Sherafat
Feb 19 '18 at 18:35
|
show 1 more comment
9
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
3
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
11
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
21
when you generate an new component with CLI you can add--spec=falseto exclude the generation of a spec file. The full command for generating a new component would be:ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component
– Dean
May 31 '17 at 19:14
5
this can be disabled by modifyingangular-cli.jsonlike this:{ "defaults": { "component": { "spec": false } } }
– Ali Sherafat
Feb 19 '18 at 18:35
9
9
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
Thanks, I was wondering this myself. Suppose I don't want to run any tests, can I safely delete the .spec files? (and also the test folders and files such as the e2e folder?)
– Kokodoko
Nov 29 '16 at 16:56
3
3
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
I also feel like this question requires a little more answering. Can we just totally ignore these files and just go about our work ?
– Mateusz Migała
Feb 8 '17 at 10:18
11
11
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
As awiseman states, the spec files are indeed for testing of you application. If you don't want to use the test files you can simply delete or ignore them. Your project will continue to function without the spec files.
– dennismuijs
Feb 13 '17 at 13:55
21
21
when you generate an new component with CLI you can add
--spec=false to exclude the generation of a spec file. The full command for generating a new component would be: ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component– Dean
May 31 '17 at 19:14
when you generate an new component with CLI you can add
--spec=false to exclude the generation of a spec file. The full command for generating a new component would be: ng g component comp-name --spec=false. More info here: github.com/angular/angular-cli/wiki/generate-component– Dean
May 31 '17 at 19:14
5
5
this can be disabled by modifying
angular-cli.json like this: { "defaults": { "component": { "spec": false } } }– Ali Sherafat
Feb 19 '18 at 18:35
this can be disabled by modifying
angular-cli.json like this: { "defaults": { "component": { "spec": false } } }– Ali Sherafat
Feb 19 '18 at 18:35
|
show 1 more comment
if you generate new angular project using "ng new", you may skip a generating of spec.ts files. For this you should apply --skip-tests option.
ng new ng-app-name --skip-tests
add a comment |
if you generate new angular project using "ng new", you may skip a generating of spec.ts files. For this you should apply --skip-tests option.
ng new ng-app-name --skip-tests
add a comment |
if you generate new angular project using "ng new", you may skip a generating of spec.ts files. For this you should apply --skip-tests option.
ng new ng-app-name --skip-tests
if you generate new angular project using "ng new", you may skip a generating of spec.ts files. For this you should apply --skip-tests option.
ng new ng-app-name --skip-tests
answered Jun 14 '18 at 20:23
trueborodatrueboroda
880915
880915
add a comment |
add a comment |
The .spec.ts files are for unit tests for individual components.
You can run Karma task runner through ng test. In order to see code coverage of unit test cases for particular components run ng test --code-coverage
add a comment |
The .spec.ts files are for unit tests for individual components.
You can run Karma task runner through ng test. In order to see code coverage of unit test cases for particular components run ng test --code-coverage
add a comment |
The .spec.ts files are for unit tests for individual components.
You can run Karma task runner through ng test. In order to see code coverage of unit test cases for particular components run ng test --code-coverage
The .spec.ts files are for unit tests for individual components.
You can run Karma task runner through ng test. In order to see code coverage of unit test cases for particular components run ng test --code-coverage
answered Jul 19 '18 at 17:55
Pritam SinhaPritam Sinha
113
113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37502809%2fwhat-are-the-spec-ts-files-generated-by-angular-cli-for%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown