- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在编写 TestBed 单元测试。
有一个特定的组件,它是被测组件的子组件。该子组件在测试运行时会导致错误。该子组件与测试本身无关;这只会引起问题。
我想用一个虚拟的替换它,或者阻止它被添加。
有问题的组件来自被测组件模块的其他模块。
我试图制作一个 stub /虚拟:
@Component({
selector : 'problematic-component-selector',
template : 'FAKE CAPTCHA',
})
export class ProblematicComponentStubComponent {
}
这是我的beforeEach
:
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
FormsModule,
RouterModule,
ModuleOfProblematicComponent,
],
declarations: [
ComponentUnderTest,
ProblematicComponentStubComponent, /* NOTE: here I tried to declare the fake one */
],
providers: [
{ provide: Router, useClass: RouterStub },
{ provide: ActivatedRoute, useClass: Stub },
],
我试图覆盖组件模板,以防止错误:
TestBed.overrideComponent(ProblematicComponent, {
set: {
template: 'Fake Captcha' // prevent ReCaptcha error
}
})
我知道 NO_ERRORS_SCHEMA
,但没有帮助。
我也在试验 overrideModule
,但没有成功:
TestBed.overrideModule(ModuleOfProblematicComponent, {
remove: {
declarations: [ProblematicComponent],
},
add: {
declarations: [ProblematicComponentStubComponent],
}
});
因此,问题是:是否可以覆盖 ProblematicComponent
(它位于 ComponentUnderTest
模块以外的模块中?
最佳答案
TestBed#overrideComponent
方法将帮助您替换 TestBed 中任何组件的模板。如果还不够,请使用 TestBed#overrideModule
替换整个组件(模板和类)。
文档松散:https://angular.io/api/core/testing/TestBed
测试也可能有帮助: https://github.com/angular/angular/blob/master/packages/platform-browser/test/testing_public_spec.ts
关于angular - 在 Angular TestBed 的另一个模块中覆盖组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224526/
我有一个组件,它有两个依赖项:一个是 LOCALE_ID在 Angular 中全局定义,另一种是语言,在组件中定义为 { provide: LANGUAGE_TOKEN, useValue: navi
我正在尝试测试一个具有依赖性的简单组件。我试图模拟这种依赖关系,但真正的服务仍在构建中。有人能看出我错过了什么吗? 这是我的组件: import { Component } from "@angula
import java.util.Random; public class TestBed { public static void main(String a[]) { // creatin
我目前正在尝试为在其 html 中使用另一个组件标记的组件编写一组单元测试。 但是我似乎无法编译这个其他组件。我尝试了几种使用 NO_ERROR_SCHEMA 的方
我有 MainComponent,它使用 ChildComponentA 作为 @ViewChild。 MainComponent 正在调用 ChildComponentA 上的方法。 我想编写一个模
当对测试夹具使用以下配置时,我收到无法找到标签的投诉。直接在 AppModule 中替换 MockSelectionToolComponent 工作正常,所以一定是别的东西...... // Add
在基于 Angular 8.1.2 和 Ionic 4 的应用程序项目中,我为 typescript 中的一个简单类编写了单元测试。这与“npm test”配合得很好。为了准备需要模拟的更复杂的类,我
可以说我有一个如下所示的测试配置 TestBed.configureTestingModule({ imports: [HttpClientTestingModule],
我正在尝试测试在 App Engine 上运行的应用程序。我正在使用 the Testbed framework ,到目前为止,除了以下意外行为外,它就像一个魅力: 像这样的测试将工作得很好(没有框架
如何使用另一个提供者的实例在 TestBed.configureTestingModule() 中实例化一个提供者? 一个例子(显然不起作用): beforeEach(() => { TestBe
我正在使用 TestBed 进行 Angular 2+ 单元测试。场景,我想验证我的组件,即伪元素的颜色。 组件.ts label::before { right: 0;
我想了解这个 testb 指令 (x86-64) 会做什么。 testb $1, %al 这里 $1 的值(value)是多少。是全部 (0xFF) 还是单个 1 (0x1)? 程序集由 clang
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
我正在编写 TestBed 单元测试。 有一个特定的组件,它是被测组件的子组件。该子组件在测试运行时会导致错误。该子组件与测试本身无关;这只会引起问题。 我想用一个虚拟的替换它,或者阻止它被添加。 有
我是 Angular 2 的 Jasmine 新手,在编写测试用例时我经常使用 TestBed 对象并收到错误:请在测试前调用“TestBed.compileComponents”。 如何解决这个错误
我们正在使用 TestBed.overrideComponent(CoolComponent, { set: { template: 'i am the fake componen
我使用 Angular TestBed 进行了一些单元测试。即使测试非常简单,它们运行起来也非常慢(平均每秒 1 个测试 Assets )。 即使在重新阅读 Angular 文档后,我也找不到性能如此
我有一个组件,它接收组件的组件类以动态创建为子组件。 let componentFactory = this.componentFactoryResolver.resolveComponentFact
我正在使用带有 Jest 的 Angular 7 并且正在模拟组件的提供者。很多时候我需要更改在 TestBed 之后注入(inject)到组件中的内容。已编译,并且使用此代码执行此操作没有任何问题:
我实际上正在尝试构建一个 flutter 应用程序窗口,但我收到了这条错误消息: flutter build windows CMake Error:
我是一名优秀的程序员,十分优秀!