ComponentFixture
用于调试和测试组件的夹具。
Fixture for debugging and testing a component.
class ComponentFixture<T> {
constructor(componentRef: ComponentRef<T>, ngZone: NgZone, _autoDetect: boolean)
debugElement: DebugElement
componentInstance: T
nativeElement: any
elementRef: ElementRef
changeDetectorRef: ChangeDetectorRef
componentRef: ComponentRef<T>
ngZone: NgZone | null
detectChanges(checkNoChanges: boolean = true): void
checkNoChanges(): void
autoDetectChanges(autoDetect: boolean = true)
isStable(): boolean
whenStable(): Promise<any>
whenRenderingDone(): Promise<any>
destroy(): void
}
构造函数
参数
|
属性
属性 | 说明 |
---|---|
debugElement: DebugElement | 与该组件的根元素关联的 DebugElement。 The DebugElement associated with the root element of this component. |
componentInstance: T | 根组件类的实例。 The instance of the root component class. |
nativeElement: any | 组件根部的原生元素。 The native element at the root of the component. |
elementRef: ElementRef | 位于组件根目录的元素的 ElementRef。 The ElementRef for the element at the root of the component. |
changeDetectorRef: ChangeDetectorRef | 组件的 ChangeDetectorRef The ChangeDetectorRef for the component |
componentRef: ComponentRef<T> | 声明在构造函数中 |
ngZone: NgZone | null | 声明在构造函数中 |
方法
触发组件的变更检测周期。 Trigger a change detection cycle for the component. |
进行变更检测以确保没有更改。 Do a change detection run to make sure there were no changes. |
参数没有参数。 返回值
|
设置夹具是否应自动检测变化。 Set whether the fixture should autodetect changes. |
还运行一次 detectChanges,以检测出任何现有更改。 Also runs detectChanges once so that any existing change is detected. |
返回此夹具当前是否稳定或具有尚未完成的异步任务。 Return whether the fixture is currently stable or has async tasks that have not been completed yet. |
参数没有参数。 返回值
|
当夹具稳定时解析的承诺。 Get a promise that resolves when the fixture is stable. |
参数没有参数。 返回值
|
当事件已触发异步活动或异步变更检测后,可用此方法继续执行测试。 This can be used to resume testing after events have triggered asynchronous activity or asynchronous change detection. |
获得一个承诺,可以解决以下动画中 ui 状态何时稳定的问题。 Get a promise that resolves when the ui state is stable following animations. |
参数没有参数。 返回值
|
触发组件的销毁。 Trigger component destruction. |
参数没有参数。 返回值
|