当创建一个新项目时,ng 测试工作正常,之后我添加了 Primeng 和 Bootstrap 库,现在我收到错误“预计在‘proxyzone’中运行,但未找到”我没有使用“fakeAsync”。代码已附上。
import 'zone.js/dist/zone-testing'
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(should have as title 'UI-design', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('UI-design');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.content span')?.textContent).toContain('UI-design app is running!');
});
});
就我而言,通过在 tsconfig 中将
compilerOptions.target
设置为 es2016
解决了错误。