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

Function expectStableTexts

packages/core/test/application_ref_spec.ts:862–882  ·  view source on GitHub ↗
(component: Type<any>, expected: string[])

Source from the content-addressed store, hash-verified

860 });
861
862 async function expectStableTexts(component: Type<any>, expected: string[]) {
863 const fixture = TestBed.createComponent(component);
864 const appRef: ApplicationRef = TestBed.inject(ApplicationRef);
865 const zone: NgZone = TestBed.inject(NgZone);
866 appRef.attachView(fixture.componentRef.hostView);
867 zone.run(() => appRef.tick());
868
869 let i = 0;
870 const {promise, resolve} = Promise.withResolvers<void>();
871 const sub = appRef.isStable.subscribe({
872 next: (stable: boolean) => {
873 if (stable) {
874 expect(i).toBeLessThan(expected.length);
875 expect(fixture.nativeElement).toHaveText(expected[i++]);
876 resolve();
877 }
878 },
879 });
880 fixture.debugElement.injector.get(DestroyRef).onDestroy(() => sub.unsubscribe());
881 await promise;
882 }
883
884 it('isStable should fire on synchronous component loading', async () => {
885 await expectStableTexts(SyncComp, ['1']);

Callers 1

Calls 12

attachViewMethod · 0.80
toHaveTextMethod · 0.80
createComponentMethod · 0.65
injectMethod · 0.65
runMethod · 0.65
tickMethod · 0.65
withResolversMethod · 0.65
subscribeMethod · 0.65
onDestroyMethod · 0.65
getMethod · 0.65
unsubscribeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected