gpt4 book ai didi

angular Testbed overrideModule 不工作

转载 作者:太空狗 更新时间:2023-10-29 17:46:24 26 4
gpt4 key购买 nike

当对测试夹具使用以下配置时,我收到无法找到标签的投诉。直接在 AppModule 中替换 MockSelectionToolComponent 工作正常,所以一定是别的东西......

 // Add the imported module to the imports array in beforeEach
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MockSelectionToolComponent],
imports: [

AppModule
]
}).overrideModule(AppModule, {
remove: {
declarations: [SelectionToolComponent]
}
}).compileComponents();

fixture = TestBed.createComponent(MappingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.initialiseMap();
});

Error: Template parse errors: 'app-selection-tool' is not a known element:

最佳答案

所以实际上我们并没有把它加到测试模块的声明中,而是加到原来的Module中:

// Add the imported module to the imports array in beforeEach
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [],
imports: [

AppModule
]
}).overrideModule(AppModule, {
remove: {
declarations: [SelectionToolComponent]
},
add: {
declarations: [MockSelectionToolComponent]
}
}).compileComponents();

fixture = TestBed.createComponent(MappingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.initialiseMap();
});

祝你好运,发现任何地方都有记录。

关于angular Testbed overrideModule 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44758067/

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