带Jest单元测试的Angular 6
我使用Angular 6()克隆了一个初学者项目。我移除了因果报应,转而安装了玩笑。站点加载正常,但单元测试失败,出现以下错误:带Jest单元测试的Angular 6,angular,jestjs,jest-preset-angular,Angular,Jestjs,Jest Preset Angular,我使用Angular 6()克隆了一个初学者项目。我移除了因果报应,转而安装了玩笑。站点加载正常,但单元测试失败,出现以下错误: Illegal state: Could not load the summary for directive AppComponent. at syntaxError (../../../../../execroot/angular/packages/compiler/src/util.ts:100:17) at CompileMetadataResolve
Illegal state: Could not load the summary for directive AppComponent.
at syntaxError (../../../../../execroot/angular/packages/compiler/src/util.ts:100:17)
at CompileMetadataResolver.Object.<anonymous>.CompileMetadataResolver.getDirectiveSummary (../../../../../execroot/angular/packages/compiler/src/metadata_resolver.ts:426:11)...
app.component.test.ts:
import { AppModule } from "./app.module";
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
import { APP_BASE_HREF } from '@angular/common';
import { Router } from '@angular/router';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(() => {
class loading = { return { events: {} } };
class router = {};
TestBed.configureTestingModule({
// imports: [AppModule], // didn't help
declarations: [
AppComponent
],
providers: [
AppComponent,
// { provide: APP_BASE_HREF, useValue: '/' }, // didn't help
{ provide: SlimLoadingBarService, useClass: loading },
{ provide: Router, useClass: router }
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
});
});
我是否需要一些特别的东西,让玩笑和天使一起工作?谢谢 我相信建议使用ts jest,但我使用jest 23,但不是最新的,也不是Angular 6。如果您使用
jest preset ANGUAL
,我根据问题标签假设,并且您根据设置所有内容,它应该可以工作
import { AppModule } from "./app.module";
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
import { APP_BASE_HREF } from '@angular/common';
import { Router } from '@angular/router';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(() => {
class loading = { return { events: {} } };
class router = {};
TestBed.configureTestingModule({
// imports: [AppModule], // didn't help
declarations: [
AppComponent
],
providers: [
AppComponent,
// { provide: APP_BASE_HREF, useValue: '/' }, // didn't help
{ provide: SlimLoadingBarService, useClass: loading },
{ provide: Router, useClass: router }
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
});
});