所以我遇到了这个问题,为 Angular 4 应用程序进行单元测试
发生的情况是它不断给出问题标题中所述的错误。
我尝试用谷歌搜索它,尝试导入一大堆不同的模块,最后发现这个“平台”的一个接近答案可能是来自@angular/browser
Platform.js 的 browserModule。
所以在我的单元测试中,我尝试导入它并声明它,但它没有帮助。
谁能帮忙解决这个问题,因为我什至不确定这个“平台”是什么?
问题:错误中的这个“平台”到底是什么以及如何解决?
谢谢。
我附上了我的代码如下:
import { ComponentFixture, TestBed, async} from "@angular/core/testing";
import { DebugElement, CUSTOM_ELEMENTS_SCHEMA, PlatformRef} from
"@angular/core";
import { TeamCreationAssignmentComponent } from "./team-creation-assignment.component";
import { OdmService } from "../../services/odm/odm.service";
import { UserNotificationService } from "../../services/user/user-notification.service";
import { MatSnackBar } from "@angular/material";
import { OVERLAY_PROVIDERS, ScrollStrategyOptions, ScrollDispatcher} from "@angular/cdk/overlay";
describe('Team creation assignment component', () => {
let comp: TeamCreationAssignmentComponent;
let fixture: ComponentFixture<TeamCreationAssignmentComponent>;
let odmServiceSub = {};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TeamCreationAssignmentComponent],
//imports: [BrowserModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
{provide: OdmService, useValue: odmServiceSub},
UserNotificationService,
MatSnackBar,
OVERLAY_PROVIDERS,
ScrollStrategyOptions,
ScrollDispatcher,
],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TeamCreationAssignmentComponent);
comp = fixture.componentInstance;
});
it('should have defined component', () => {
expect(comp).toBeDefined();
})
});