使用“ng test”升级 Angular v9 后无法设置基本提供程序错误

dcp*_*450 6 unit-testing angular-cli angular

从 v8 升级到 v9 后,我已经更新并通过了所有单元测试。但是,现在我收到以下错误:

Cannot set base providers because it has already been called

研究表明我在申请中打过两次电话BrowserDynamicTestingModuleplatformBrowserDynamicTesting()我搜索了整个应用程序,只在我的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);
Run Code Online (Sandbox Code Playgroud)

我不确定错误还可能来自哪里。