Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/core/test/component_fixture_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ export function main() {
});
}));

it('should signal through whenRenderingDone when the fixture is stable', async(() => {
const componentFixture = TestBed.createComponent(AsyncComp);

componentFixture.detectChanges();
expect(componentFixture.nativeElement).toHaveText('1');

const element = componentFixture.debugElement.children[0];
dispatchEvent(element.nativeElement, 'click');
expect(componentFixture.nativeElement).toHaveText('1');

// Component is updated asynchronously. Wait for the fixture to become stable
// before checking.
componentFixture.whenRenderingDone().then((waited) => {
expect(waited).toBe(true);
componentFixture.detectChanges();
expect(componentFixture.nativeElement).toHaveText('11');
});
}));

it('should wait for macroTask(setTimeout) while checking for whenStable ' +
'(autoDetectChanges)',
async(() => {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/testing/src/component_fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ export class ComponentFixture<T> {
}
}

/**
* Get a promise that resolves when the ui state is stable following animations.
*/
whenRenderingDone(): Promise<any> {
// this is temporary until this is functional
return this.whenStable();
}

/**
* Trigger component destruction.
*/
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/core/testing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export declare class ComponentFixture<T> {
destroy(): void;
detectChanges(checkNoChanges?: boolean): void;
isStable(): boolean;
whenRenderingDone(): Promise<any>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the right name? when I look at whenStable and whenRenderingDone how should I know which one to choose without reading the api docs?

Maybe whenAnimated() or whenRendered()? "rendered" is however ambiguous because rendering is a just a snapshot of a animation, so at any point during animation the UI is rendered, it's just not fully animated.

Are there any other related api additions that could help us pick the right name? Looking at the overall api surface provides the best guidance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed this more with @matsko and I'm fine with the name. all the alternatives are not great.

whenStable(): Promise<any>;
}

Expand Down