我试着用玩笑来写角度测试:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BookListComponent],
}).compileComponents();
}));
当我发射时:
npm run test:watch
我发现了一个错误:
错误TS2304: C找不到名字‘异步’。
发布于 2020-12-02 16:13:31
你必须在角11中将async
改为waitForAsync
,因为它们改变了它。他们更改了它,因为您从早期版本中从async
导入的@angular/core/testing
与本机async
of JavaScript相似,可能会造成混淆。
import { waitForAsync } from '@angular/core/testing';
.....
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [BookListComponent],
}).compileComponents();
}));
链接到waitForAsync。
发布于 2020-12-02 16:12:14
async
不是一个函数。试着这样做:
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [BookListComponent],
}).compileComponents();
});
我不确定您是否需要将函数标记为异步,因为您没有在每个函数中使用等待。
看看文档
https://stackoverflow.com/questions/65109920
复制相似问题