填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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)
      
      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
      
      detectChanges(checkNoChanges: boolean = true): void
    
引數
checkNoChanges boolean
可選. 預設值是 `true`.
返回值

void

進行變更檢測以確保沒有更改。

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

checkNoChanges(): void
      
      checkNoChanges(): void
    
引數

沒有引數。

返回值

void

設定夾具是否應自動檢測變化。

Set whether the fixture should autodetect changes.

autoDetectChanges(autoDetect: boolean = true)
      
      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
      
      isStable(): boolean
    
引數

沒有引數。

返回值

boolean

當夾具穩定時解析的承諾。

Get a promise that resolves when the fixture is stable.

whenStable(): Promise<any>
      
      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>
      
      whenRenderingDone(): Promise<any>
    
引數

沒有引數。

返回值

Promise<any>

觸發元件的銷燬。

Trigger component destruction.

destroy(): void
      
      destroy(): void
    
引數

沒有引數。

返回值

void