如何解决从 Angular 11.0.3 开始,e2e 测试产生错误
从 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
谢谢!
解决方法
确保更新您的 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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。