我正在使用Angular CLI来生成和服务项目。它似乎工作得很好——尽管对于我的小学习项目来说,它产生的东西比我需要的要多——但这是意料之中的。
我注意到它会为项目中的每个Angular元素(组件、服务、管道等)生成spec.ts。我到处找,但没有找到解释这些文件是干什么用的。
这些构建文件是使用tsc时通常隐藏的吗?我之所以这么想,是因为我想更改我创建的一个命名糟糕的组件的名称,并发现该名称也在这些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 {
}