MCPcopy Index your code
hub / github.com/angular/angular / ComponentFixture

Class ComponentFixture

packages/core/testing/src/component_fixture.ts:47–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45 * @publicApi
46 */
47export class ComponentFixture<T> {
48 /**
49 * The DebugElement associated with the root element of this component.
50 */
51 debugElement: DebugElement;
52
53 /**
54 * The instance of the root component class.
55 */
56 componentInstance: T;
57
58 /**
59 * The native element at the root of the component.
60 */
61 nativeElement: any;
62
63 /**
64 * The ElementRef for the element at the root of the component.
65 */
66 elementRef: ElementRef;
67
68 /**
69 * The ChangeDetectorRef for the component
70 */
71 changeDetectorRef: ChangeDetectorRef;
72
73 private _renderer: RendererFactory2 | null | undefined;
74 private _isDestroyed: boolean = false;
75 /** @internal */
76 protected readonly _noZoneOptionIsSet = inject(ComponentFixtureNoNgZone, {optional: true});
77 /** @internal */
78 protected _ngZone: NgZone = this._noZoneOptionIsSet ? new NoopNgZone() : inject(NgZone);
79 // Inject ApplicationRef to ensure NgZone stableness causes after render hooks to run
80 // This will likely happen as a result of fixture.detectChanges because it calls ngZone.run
81 // This is a crazy way of doing things but hey, it's the world we live in.
82 // The zoneless scheduler should instead do this more imperatively by attaching
83 // the `ComponentRef` to `ApplicationRef` and calling `appRef.tick` as the `detectChanges`
84 // behavior.
85 /** @internal */
86 protected readonly _appRef = inject(ApplicationRef);
87 private readonly _testAppRef = this._appRef as unknown as TestAppRef;
88 private readonly pendingTasks = inject(PendingTasksInternal);
89 private readonly appErrorHandler = inject(TestBedApplicationErrorHandler);
90 private readonly zonelessEnabled = inject(ZONELESS_ENABLED);
91 private readonly scheduler = inject(ɵChangeDetectionScheduler);
92 private readonly rootEffectScheduler = inject(EffectScheduler);
93 private readonly autoDetectDefault = this.zonelessEnabled ? true : false;
94 private autoDetect =
95 inject(ComponentFixtureAutoDetect, {optional: true}) ?? this.autoDetectDefault;
96
97 private subscriptions = new Subscription();
98
99 // TODO(atscott): Remove this from public API
100 ngZone = this._noZoneOptionIsSet ? null : this._ngZone;
101
102 /** @docs-private */
103 constructor(public componentRef: ComponentRef<T>) {
104 this.changeDetectorRef = componentRef.changeDetectorRef;

Callers

nothing calls this directly

Calls 1

injectFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…