使用 jest 测试 Angular 11 时找不到名称“async”

Kha*_*ara 4 typescript jestjs angular

我正在尝试使用 jest 编写 Angular 测试:

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [BookListComponent],
    }).compileComponents();
  }));
Run Code Online (Sandbox Code Playgroud)

当我启动时:

npm run test:watch 
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

错误 TS2304:C 找不到名称“async”。

Ali*_*F50 7

你必须更改asyncwaitForAsyncAngular 11,因为他们更改了它。他们更改了它,因为async您在以前的版本中导入的内容@angular/core/testing与 JavaScript 的本机类似async,可能会导致混乱。

import { waitForAsync } from '@angular/core/testing';
.....
beforeEach(waitForAsync(() => {
    TestBed.configureTestingModule({
      declarations: [BookListComponent],
    }).compileComponents();
  }));
Run Code Online (Sandbox Code Playgroud)

waitForAsync的链接。