Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

ComponentFixture

Fixture for debugging and testing a component.

      
      abstract class ComponentFixture<T> {
  debugElement: DebugElement
  componentInstance: T
  nativeElement: any
  elementRef: ElementRef
  changeDetectorRef: ChangeDetectorRef
  ngZone: this._noZoneOptionIsSet ? null : this._ngZone
  componentRef: ComponentRef<T>
abstract detectChanges(checkNoChanges?: boolean): void
checkNoChanges(): void
abstract autoDetectChanges(autoDetect?: boolean): void
abstract isStable(): boolean
abstract whenStable(): Promise<any>
getDeferBlocks(): Promise<DeferBlockFixture[]>
whenRenderingDone(): Promise<any>
destroy(): void }

Properties

Property Description
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

The ElementRef for the element at the root of the component.

changeDetectorRef: ChangeDetectorRef

The ChangeDetectorRef for the component

ngZone: this._noZoneOptionIsSet ? null : this._ngZone
componentRef: ComponentRef<T>

Methods

Trigger a change detection cycle for the component.

      
      abstract detectChanges(checkNoChanges?: boolean): void
    
Parameters
checkNoChanges boolean

Optional. Default is undefined.

Returns

void

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

      
      checkNoChanges(): void
    
Parameters

There are no parameters.

Returns

void

Set whether the fixture should autodetect changes.

      
      abstract autoDetectChanges(autoDetect?: boolean): void
    
Parameters
autoDetect boolean

Optional. Default is undefined.

Returns

void

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.

      
      abstract isStable(): boolean
    
Parameters

There are no parameters.

Returns

boolean

Get a promise that resolves when the fixture is stable.

      
      abstract whenStable(): Promise<any>
    
Parameters

There are no parameters.

Returns

Promise<any>

This can be used to resume testing after events have triggered asynchronous activity or asynchronous change detection.

Retrieves all defer block fixtures in the component fixture.

      
      getDeferBlocks(): Promise<DeferBlockFixture[]>
    
Parameters

There are no parameters.

Returns

Promise<DeferBlockFixture[]>

Get a promise that resolves when the ui state is stable following animations.

      
      whenRenderingDone(): Promise<any>
    
Parameters

There are no parameters.

Returns

Promise<any>

Trigger component destruction.

      
      destroy(): void
    
Parameters

There are no parameters.

Returns

void