MCPcopy Create free account
hub / github.com/angular/angular / constructor

Function constructor

packages/core/testing/src/fixture.ts:88–127  ·  view source on GitHub ↗

@docs-private

(protected readonly hostRef: ComponentRef<unknown>)

Source from the content-addressed store, hash-verified

86
87 /** @docs-private */
88 constructor(protected readonly hostRef: ComponentRef<unknown>) {
89 this.changeDetectorRef = hostRef.changeDetectorRef;
90 this.debugElement = getDebugNode(hostRef.location.nativeElement) as DebugElement;
91 this.nativeElement = hostRef.location.nativeElement;
92 this.elementRef = hostRef.location;
93 this.hostView = hostRef.hostView;
94 this._testAppRef.allTestViews.add(this.hostView);
95
96 if (this.autoDetect) {
97 this._testAppRef.autoDetectTestViews.add(this.hostView);
98 this.scheduler?.notify(ɵNotificationSource.ViewAttached);
99 this.scheduler?.notify(ɵNotificationSource.MarkAncestorsForTraversal);
100 }
101 this.hostView.onDestroy(() => {
102 this._testAppRef.allTestViews.delete(this.hostView);
103 this._testAppRef.autoDetectTestViews.delete(this.hostView);
104 });
105 // Create subscriptions outside the NgZone so that the callbacks run outside
106 // of NgZone.
107 this._ngZone.runOutsideAngular(() => {
108 this.subscriptions.add(
109 this._ngZone.onError.subscribe({
110 next: (error: any) => {
111 // The rethrow here is to ensure that errors don't go unreported. Since `NgZone.onHandleError` returns `false`,
112 // ZoneJS will not throw the error coming out of a task. Instead, the handling is defined by
113 // the chain of parent delegates and whether they indicate the error is handled in some way (by returning `false`).
114 // Unfortunately, 'onError' does not forward the information about whether the error was handled by a parent zone
115 // so cannot know here whether throwing is appropriate. As a half-solution, we can check to see if we're inside
116 // a fakeAsync context, which we know has its own error handling.
117 // https://github.com/angular/angular/blob/db2f2d99c82aae52d8a0ae46616c6411d070b35e/packages/zone.js/lib/zone-spec/fake-async-test.ts#L783-L784
118 // https://github.com/angular/angular/blob/db2f2d99c82aae52d8a0ae46616c6411d070b35e/packages/zone.js/lib/zone-spec/fake-async-test.ts#L473-L478
119 if (typeof Zone === 'undefined' || Zone.current.get('FakeAsyncTestZoneSpec')) {
120 return;
121 }
122 throw error;
123 },
124 }),
125 );
126 });
127 }
128
129 /**
130 * Trigger a change detection cycle for the component.

Callers

nothing calls this directly

Calls 8

getDebugNodeFunction · 0.90
addMethod · 0.65
notifyMethod · 0.65
onDestroyMethod · 0.65
subscribeMethod · 0.65
getMethod · 0.65
deleteMethod · 0.45
runOutsideAngularMethod · 0.45

Tested by

no test coverage detected