我是Angular 2(和Angular一般...)的新手,并且发现它非常吸引人。我在用 Angular CLi生成和服务项目。它似乎运行良好-尽管对于我的小学习项目,它产生的产量超出了我的需要-但这是可以预期的。
我注意到它会产生 spec.ts
为项目中的每个Angular元素(组件,服务,管道等)生成。我到处搜索,但没有找到这些文件的用途说明。
这些构建文件在使用时通常是隐藏的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 {
}