angular - 使用“ng test”升级 Angular v9 后无法设置基本提供程序错误
问题描述
从 v8 升级到 v9 后,我的所有单元测试都已更新并通过。但是,现在我收到以下错误:
Cannot set base providers because it has already been called
研究表明,我在申请中曾打过电话BrowserDynamicTestingModule
或platformBrowserDynamicTesting()
打过两次电话。我搜索了我的整个应用程序,但在我的test.ts
文件中只找到了一次:
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
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);
我不确定错误可能来自哪里。
解决方案
推荐阅读
- javascript - 我如何在 discord.js 中每 10 秒编辑一次嵌入
- plotly-dash - 如何使用 Dash 在数据表的单元格中创建链接(url)
- awk - 使用 awk 进行系统调用
- python - 如何正确地将代理轮换器添加到脚本中?
- python - multiprocessing.pool() 无限期挂起
- c# - 在现有的 chrome 浏览器上运行 selenium?
- javascript - 从 url 获取信息
- python - 使用用户 ID 将人员添加到不和谐服务器
- javascript - 禁用包含某个类的所有元素的点击事件
- matlab - matlab中任意x,y坐标的二维中值滤波器