【问题标题】:Since Angular 11.0.3, e2e tests produce error从 Angular 11.0.3 开始,e2e 测试会产生错误
【发布时间】:2021-03-31 09:06:00
【问题描述】:

自 11.0.3 angular/core 版本以来,E2E 测试不适用于默认配置的项目。

我打开了一个问题 https://github.com/angular/angular/issues/40221,但它似乎不是回归 (?)

????最小复制

https://github.com/BrunoBeraudPW/issue-angular-11.0.3

这是一个默认项目 Angular 11.0.3,我已将所有包更新到最新版本

我已经“手动”更新了所有软件包,因为“ng new”cmd 正在创建一个 angular 10 应用程序,所以我认为问题可能是由于其他软件包而出现的。

但即使我刚刚更新了 Angular 包,错误仍然存​​在

????异常或错误

使用 fakeAsync 时:

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

selenium-webdriver 库中的几个错误(承诺)

C:\dev-phoenix\1-Photoweb-Forks\test\node_modules\selenium-webdriver\lib\promise.js:3067:27
              this.pending_ = {task: task, q: this.subQ_};
              task.promise.queue_ = this;
              result = this.subQ_.execute_(task.execute);
                                  ~
              this.subQ_.start();
            } catch (ex) {

internal/modules/cjs/loader.js 中的几个错误

internal/modules/cjs/loader.js:955:30
jasmine-spec-reporter: unable to open 'internal/modules/cjs/loader.js'
Error: ENOENT: no such file or directory, open 'internal/modules/cjs/loader.js'

它似乎无法识别 jasmine 函数,它用红色下划线标出了主要函数的名称 describe、it、fit 等,就像它不包含 test.ts 及其 import 'zone.js/dist/区域测试';

????环境

**Angular Version:**
@angular-devkit/architect       0.1100.3
@angular-devkit/build-angular   0.1100.3
@angular-devkit/core            11.0.3
@angular-devkit/schematics      11.0.3
@schematics/angular             11.0.3
@schematics/update              0.1100.3
rxjs                            6.6.3
typescript                      4.0.5

谢谢!

【问题讨论】:

  • 你好有同样的问题,但不是 e2e 测试,而是单元测试(业力)。将核心和 cli 降级到 11.0.2 版,它再次对我有用。在我看来像一个角度问题。

标签: angular jasmine protractor zone.js e2e


【解决方案1】:

确保更新您的 test.ts 文件。区域导入必须在区域测试导入之前。

import "zone.js/dist/zone";
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: {
  context(path: string, deep?: boolean, filter?: RegExp): {
    keys(): string[];
    <T>(id: string): T;
  };
};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

或者可能缺少 src/polyfills.ts 文件/缺少导入:

import 'zone.js/dist/zone';  // Included with Angular CLI.

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,升级到 Angular 11 后,运行在 Angular 10 上运行良好的 E2E 脚本不再工作。

    但是,我遇到了一个稍微不同的问题,我的 25% 的测试文件因有关 fakeAsync 的错误而失败,而其余的则成功。这使我走上了一条注释代码的道路,以了解我需要做些什么来完成这项工作。

    我发现我的一个 E2E 模型类正在导入我们的另一个库以用于通用代码。这个通用库还有包含 fakeAsync 的单元测试助手。当我将特定功能引入我的 e2e 项目并且不再引用我的其他库时,我的 E2E 脚本再次开始传递。

    总而言之,检查您的 E2E 代码是否从其他库导入并删除它们,直到您的脚本开始工作。我还建议尽可能少地制作复制脚本,这样您就可以更快地获得删除和测试的每个引用的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      相关资源
      最近更新 更多