填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

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
}
    

构造函数

      
      constructor(componentRef: ComponentRef<T>, ngZone: NgZone, _autoDetect: boolean)
    
参数
componentRef ComponentRef
ngZone NgZone
_autoDetect boolean

属性

属性说明
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.

      
      detectChanges(checkNoChanges: boolean = true): void
    
参数
checkNoChanges boolean
可选. 默认值是 `true`.
返回值

void

进行变更检测以确保没有更改。

Do a change detection run to make sure there were no changes.

      
      checkNoChanges(): void
    
参数

没有参数。

返回值

void

设置夹具是否应自动检测变化。

Set whether the fixture should autodetect changes.

      
      autoDetectChanges(autoDetect: boolean = true)
    
参数
autoDetect boolean
可选. 默认值是 `true`.

还运行一次 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.

      
      isStable(): boolean
    
参数

没有参数。

返回值

boolean

当夹具稳定时解析的承诺。

Get a promise that resolves when the fixture is stable.

      
      whenStable(): Promise<any>
    
参数

没有参数。

返回值

Promise<any>

当事件已触发异步活动或异步变更检测后,可用此方法继续执行测试。

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.

      
      whenRenderingDone(): Promise<any>
    
参数

没有参数。

返回值

Promise<any>

触发组件的销毁。

Trigger component destruction.

      
      destroy(): void
    
参数

没有参数。

返回值

void