我正在对有角度的项目执行单元测试,但出现错误
“未捕获的ReferenceError:未定义区域”
在茉莉花和业力中。目前,我使用的是角度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",
未捕获的ReferenceError:未定义区域 在:9876 / _karma_webpack_ / webpack:/node_modules/zone.js/dist/zone-testing.js:85 在:9876 / _karma_webpack_ / webpack:/node_modules/zone.js/dist/zone-testing.js:9 在对象。 (:9876 / _karma_webpack_ / webpack:/node_modules/zone.js/dist/zone-testing.js:12) 在Object ../ node_modules / zone.js / dist / zone-testing.js(zone-testing.js:1584) 位于 webpack_require (:9876 / _karma_webpack_ / webpack:/ webpack / bootstrap:76) 在Object ../ src / test.ts(:9876 / _karma_webpack_ / webpack:/src/test.ts:3) 位于 webpack_require (:9876 / _karma_webpack_ / webpack:/ webpack / bootstrap:76) 在checkDeferredModules(:9876 / _karma_webpack_ / webpack:/ webpack / bootstrap:43) 在:9876 / _karma_webpack_ / webpack:/ webpack / bootstrap:134 在bootstrap:134
答案 0 :(得分:2)
我在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);
答案 1 :(得分:0)
通过下面的链接,对您有所帮助。
https://github.com/angular/zone.js/issues/776
update employees e
set e.employee_ID = 'EMP006'
where e.employee_ID in (select e.employeeID from employees, employee_type et
where employee_type = 'CASUAL'
and e.employee_id = et.employee_id);
dbms_output.put_line('expected inserted records:44,actual:'||SQL%ROWCOUNT);
答案 2 :(得分:0)
我不知道这是否仍然是一个问题,但如果一切正常但仍然无法正常工作,请在 karma.conf.js
文件中尝试以下操作:
config.set({... files: ['node_modules/zone.js/dist/zone.js'] });
有关更多信息,请参阅此链接: Link