从 Angular 14 更新到 15 后,我的测试将不再运行。当我运行 ng test 时,出现以下错误:
An error was thrown in afterAll
Uncaught TypeError: __webpack_require__(...).context is not a function
TypeError: __webpack_require__(...).context is not a function
at Module.4289 (http://localhost:9876/_karma_webpack_/webpack:/src/test.ts:22:30)
at __webpack_require__ (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:19:1)
at __webpack_exec__ (http://localhost:9876/_karma_webpack_/main.js:180646:48)
at http://localhost:9876/_karma_webpack_/main.js:180647:54
at Function.__webpack_require__.O
Run Code Online (Sandbox Code Playgroud)
我的 test.ts 文件如下所示,并在 angular.json 中设置为“main”。
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import "zone.js/testing";
import { getTestBed } from "@angular/core/testing";
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
declare const require: …Run Code Online (Sandbox Code Playgroud)