我正在尝试找到解决此错误的解决方案:
错误:超时 - 在jasmine.default_timeout_interval
指定的超时中未调用async回调
当我使用无头浏览器运行业力单元测试时,如果使用Chrome浏览器运行,则测试通过,当我的Angular组件的HTML线很少时,测试通过。
这是我的测试文件,
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
fdescribe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
});
我的组件非常简单,只能加载html模板
import { Component } from '@angular/core';
@Component({
selector: 'pm-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
pageTitle: string = 'Angular: Getting Started';
}
ihazcode指出的解决方案,使用fakeasync代替async
import {testbed,async,fakeasync}来自'@angular/core/testing';
来自'./app.component';
的导入{appcomponent}fdescribe('AppComponent', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));