Skip to content

Commit 38c524d

Browse files
matskojasonaden
authored andcommitted
feat(core): introduce fixture.whenRenderingDone for testing (angular#16732)
1 parent 0626464 commit 38c524d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

packages/core/test/component_fixture_spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,25 @@ export function main() {
158158
});
159159
}));
160160

161+
it('should signal through whenRenderingDone when the fixture is stable', async(() => {
162+
const componentFixture = TestBed.createComponent(AsyncComp);
163+
164+
componentFixture.detectChanges();
165+
expect(componentFixture.nativeElement).toHaveText('1');
166+
167+
const element = componentFixture.debugElement.children[0];
168+
dispatchEvent(element.nativeElement, 'click');
169+
expect(componentFixture.nativeElement).toHaveText('1');
170+
171+
// Component is updated asynchronously. Wait for the fixture to become stable
172+
// before checking.
173+
componentFixture.whenRenderingDone().then((waited) => {
174+
expect(waited).toBe(true);
175+
componentFixture.detectChanges();
176+
expect(componentFixture.nativeElement).toHaveText('11');
177+
});
178+
}));
179+
161180
it('should wait for macroTask(setTimeout) while checking for whenStable ' +
162181
'(autoDetectChanges)',
163182
async(() => {

packages/core/testing/src/component_fixture.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ export class ComponentFixture<T> {
160160
}
161161
}
162162

163+
/**
164+
* Get a promise that resolves when the ui state is stable following animations.
165+
*/
166+
whenRenderingDone(): Promise<any> {
167+
// this is temporary until this is functional
168+
return this.whenStable();
169+
}
170+
163171
/**
164172
* Trigger component destruction.
165173
*/

tools/public_api_guard/core/testing.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export declare class ComponentFixture<T> {
1616
destroy(): void;
1717
detectChanges(checkNoChanges?: boolean): void;
1818
isStable(): boolean;
19+
whenRenderingDone(): Promise<any>;
1920
whenStable(): Promise<any>;
2021
}
2122

0 commit comments

Comments
 (0)