gpt4 book ai didi

javascript - 为 TestBed 提供 "entryComponents"

转载 作者:IT王子 更新时间:2023-10-29 03:15:06 28 4
gpt4 key购买 nike

我有一个组件,它接收组件的组件类以动态创建为子组件。

let componentFactory = this.componentFactoryResolver.resolveComponentFactory(componentToCreate);
this.componentReference = this.target.createComponent(componentFactory);

我正在尝试编写一个单元测试并传递一些 TestComponent 以供其创建和呈现。

TestBed
.configureTestingModule(<any>{
declarations: [MyAwesomeDynamicComponentRenderer, TestHostComponent],
entryComponents: [TestComponent],
});

因为 configureTestingModule 期望没有 entryComponentsTestModuleMetadata 但我得到错误:“没有组件工厂找到 TestComponent”。

如何向 TestBed 提供 entryComponents

最佳答案

如果你愿意,你也可以直接将它添加到你的测试文件中:

import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; // DO not forget to Import

TestBed.configureTestingModule({
declarations: [ MyDynamicComponent ],
}).overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [ MyDynamicComponent ],
}
});

关于javascript - 为 TestBed 提供 "entryComponents",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41483841/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com