我已经构建了一个没有任何规范文件的应用程序。
我使用angular-spec-generator包创建了所有规格文件。
当我运行ng test时,生成的app.component.spec.ts出现奇怪的错误:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(async(() => {
// I tryed to add theses line but nothing change
// **https://stackoverflow.com/a/49163912/11730828**
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule,
platformBrowserDynamicTesting());
TestBed.configureTestingModule({
declarations: [AppComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
这是app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: '<router-outlet></router-outlet>',
})
export class AppComponent { }
我正在与UT一起乞讨,这两个奇怪的错误无助于我调试,当我在google上找到任何东西
编辑:测试失败,组件未定义
致谢