gpt4 book ai didi

jasmine - 未捕获的 ReferenceError : Zone is not defined (Jasmine)

转载 作者:行者123 更新时间:2023-12-04 13:18:07 27 4
gpt4 key购买 nike

我正在为 angular 项目执行单元测试,但出现错误

'Uncaught ReferenceError: Zone is not defined'



在 Jasmine 和 karma 中。目前我使用 angular 6。
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"typescript": "2.7.2",

Uncaught ReferenceError: Zone is not defined at :9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:85 at :9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:9 at Object. (:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:12) at Object../node_modules/zone.js/dist/zone-testing.js (zone-testing.js:1584) at webpack_require (:9876/_karma_webpack_/webpack:/webpack/bootstrap:76) at Object../src/test.ts (:9876/_karma_webpack_/webpack:/src/test.ts:3) at webpack_require (:9876/_karma_webpack_/webpack:/webpack/bootstrap:76) at checkDeferredModules (:9876/_karma_webpack_/webpack:/webpack/bootstrap:43) at :9876/_karma_webpack_/webpack:/webpack/bootstrap:134 at bootstrap:134

最佳答案

我在 Angular 9 中遇到了同样的问题。

我已经为“test.ts”文件添加了一些导入和一个用于窗口的 polyfill。在完整文件下方。

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

(window as any).global = window;

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);

关于jasmine - 未捕获的 ReferenceError : Zone is not defined (Jasmine),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57671998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com