Angular CLI에 의해 생성되는 "spec.ts" 파일은 어떤 용도로 사용됩니까?
Angular CLI를 사용하여 프로젝트를 생성하고 서비스를 제공하고 있습니다.제 작은 학습 프로젝트에서는 필요한 것보다 더 많은 것을 만들어 낼 수 있지만, 그것은 잘 작동하는 것 같습니다.
이 때문에 이 모든 것이spec.ts
프로젝트의 각 각도 요소(구성 요소, 서비스, 파이프 등)에 대해 설명합니다.여기저기 찾아봤지만 이 파일들의 용도를 설명해주지 못했어요.
이러한 빌드 파일은 일반적으로 사용할 때 숨겨져 있습니까?tsc
이름이 좋지 않은 사람의 이름을 바꾸고 싶어서 궁금했다.Component
제가 만든 이름인데, 이 이름에서도 언급이 되어 있다는 것을 알게 되었습니다.spec.ts
파일을 표시합니다.
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 애플리케이션의 규칙은 각 .ts 파일에 대해 .spec.ts 파일을 갖는 것입니다.Karma test runner(https://karma-runner.github.io/)를 통해 Jasmine javascript 테스트 프레임워크를 사용하여 실행됩니다.ng test
명령어를 입력합니다.
이를 사용하여 다음 내용을 확인할 수 있습니다.
https://angular.io/guide/testing
"ng new"를 사용하여 새로운 각도 프로젝트를 생성할 경우 spec.ts 파일 생성을 건너뛸 수 있습니다.그러기 위해서는 --skip-tests 옵션을 적용해야 합니다.
ng ng ng-app-name --ng-app-name
.spec.ts 파일은 각 컴포넌트의 유닛 테스트용입니다.Karma 태스크 러너를 실행할 수 있습니다.ng test
특정 컴포넌트에 대한 유닛 테스트 케이스의 코드 적용 범위를 확인하기 위해ng test --code-coverage
.spec.ts
파일이 에 사용됩니다.unit testing
를 참조해 주세요.
생성하지 않으려면 을 사용하십시오.--spec=false
신규 작성 중Component
.이것처럼.
ng generate component --spec=false mycomponentName
언급URL : https://stackoverflow.com/questions/37502809/what-are-the-spec-ts-files-generated-by-angular-cli-for
'programing' 카테고리의 다른 글
"Post"에서 다른 이름으로 이름 변경 (0) | 2023.03.29 |
---|---|
WooCommerce 주문에 대한 지불 방법을 ID별로 확인하는 방법은 무엇입니까? (0) | 2023.03.29 |
React + 노드 도입 방법JS Express 애플리케이션을 AWS에 적용하시겠습니까? (0) | 2023.03.19 |
셸 스크립트로 JSON을 예쁘게 인쇄하려면 어떻게 해야 하나요? (0) | 2023.03.19 |
jQuery - ajax POST의 폼 값을 가져옵니다. (0) | 2023.03.19 |