My current go-to tool for generating and serving projects is Angular CLI. So far, it's been pretty smooth sailing – although I've noticed that for my smaller learning projects, it tends to create more than what I actually need. But hey, that's all part of the learning process.
One interesting thing I've picked up on is that Angular CLI generates a spec.ts
file for each Angular element in a project (like Components, Services, Pipes, etc). I've done some digging but haven't come across a clear explanation of the purpose of these files.
Could these be build files that are normally hidden when using tsc
? I started wondering about this when I wanted to rename a poorly named Component
I had made only to find that the name was also referenced within 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 {
}