7

我正在使用 Visual Studio Code,并尝试在 Nrwl.Nx 工作区中为 Angular 调试 Jest 测试。

这是我迄今为止尝试过的:

启动.json

{
  "version": "0.2.0",
  "configurations": [

    {
      "type": "node",
      "request": "launch",
      "name": "Jest All Tests",
      "program": "${workspaceFolder}/src/Web/Finance/client-app/node_modules/.bin/jest",
      "args": ["--runInBand"],
      "cwd": "${workspaceFolder}/src/Web/Finance/client-app/apps/finance",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "disableOptimisticBPs": true,
      "windows": {
        "program": "${workspaceFolder}/src/Web/Finance/client-app/node_modules/jest/bin/jest"
      }
    }
  ]
}

app.component.spec.ts

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import 'zone.js/dist/zone.js';
import 'zone.js/dist/async-test.js';
import 'zone.js/dist/proxy.js';

describe('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();
  }));
});

最初,我在没有从 zone.js/dist 导入任何内容的情况下运行 app.component.spec.ts 测试,但是当我在 VS Code 中运行调试器时,我会得到:

Failed: "Zone is needed for the async() test helper but could not be found. Please make sure that your environment includes zone.js/dist/zone.js"

所以我导入了你在 app.component.spec.ts 中看到的 zone.js/dist 文件

现在,当我在 VS Code 中运行调试器时,我得到了:

Expected to be running in 'ProxyZone', but it was not found.

      at Function.Object.<anonymous>.ProxyZoneSpec.assertPresent (../../node_modules/zone.js/dist/proxy.js:42:19)
      at runInTestZone (../../node_modules/zone.js/dist/async-test.js:202:23)
      at Object.<anonymous> (../../node_modules/zone.js/dist/async-test.js:168:17)

进行互联网搜索并没有为我提供有关如何解决此错误的任何信息。

4

0 回答 0