尝试在 Angular 2 中编写简单的测试,但出现environment.ts
如下错误
./web/environments/environment.ts 中的错误模块构建失败:错误:TypeScript 编译中缺少 web\environments\environment.ts。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中。
app.component.ts
import { Component} from '@angular/core';
import { environment } from '../environments/environment';
@Component({
selector: 'web-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'Test App';
constructor() {
console.log(environment);
}
}
app.component.spec.ts
import { AppComponent } from './app.component';
describe('AppComponent', () => {
it(`should 1+1`, () => {
expect(1 + 1).toEqual(2); //Success
});
it('should have component ', () => {
const component = new AppComponent(); //Throws error
// expect(component).toBeTruthy();
});
});
有什么建议吗?