W3cubDocs

/Angular

ComponentFixture

class stable

Fixture for debugging and testing a component.

class ComponentFixture<T> {
  constructor(componentRef: ComponentRef<T>, ngZone: NgZone | null, _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

constructor(componentRef: ComponentRef<T>, ngZone: NgZone | null, _autoDetect: boolean)

Parameters

componentRef

Type: ComponentRef.

ngZone

Type: NgZone | null.

_autoDetect

Type: boolean.

Properties

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

componentRef ComponentRef<T> Declared in constructor.
ngZone NgZone | null Declared in constructor.

Methods

detectChanges()

Trigger a change detection cycle for the component.

detectChanges(checkNoChanges: boolean = true): void

Parameters

checkNoChanges

Type: boolean.

Optional. Default is true.

Returns

void

checkNoChanges()

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

checkNoChanges(): void

Parameters

There are no parameters.

Returns

void

autoDetectChanges()

Set whether the fixture should autodetect changes.

autoDetectChanges(autoDetect: boolean = true)

Parameters

autoDetect

Type: boolean.

Optional. Default is true.

Also runs detectChanges once so that any existing change is detected.

isStable()

Return whether the fixture is currently stable or has async tasks that have not been completed yet.

isStable(): boolean

Parameters

There are no parameters.

Returns

boolean

whenStable()

Get a promise that resolves when the fixture is stable.

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.

whenRenderingDone()

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

whenRenderingDone(): Promise<any>

Parameters

There are no parameters.

Returns

Promise<any>

destroy()

Trigger component destruction.

destroy(): void

Parameters

There are no parameters.

Returns

void

© 2010–2018 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/core/testing/ComponentFixture