-
Notifications
You must be signed in to change notification settings - Fork 27k
feat(testing): Use NgZone in TestComponentBuilder. #8301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
cc @tbosch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not a big deal, but could we use createNgZone from angular2/src/core/application_ref?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Instantiating the test component within an NgZone will let us track async tasks in event handlers and change detection. We can also do auto change detection when triggering events through dispatchEvent and not have to do fixture.detectChange() manually in the test. New API: ComponentFixture.autoDetectChanges() - This puts the fixture in auto detect mode that automatically calls detectChanges when the microtask queue is empty (Similar to how change detection is triggered in an actual application). ComponentFixture.isStable() - This returns a boolean whether the fixture is currently stable or has some async tasks that need to be completed. ComponentFixture.whenStable() - This returns a promise that is resolved when the fixture is stable after all async tasks are complete.
|
Merging PR #8301 on behalf of @mprobst to branch presubmit-mprobst-pr-8301. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Instantiating the test component within an NgZone will let us track async tasks in event handlers and change detection.
We can also do auto change detection when triggering events through dispatchEvent and not have to do fixture.detectChange() manually in the test.
New API:
ComponentFixture.autoDetectChanges() - This puts the fixture auto detect mode that automatically calls detectChanges when the microtask queue is empty (Similar to how change detection is triggered in an actual application).
ComponentFixture.isStable() - This returns a promise that is resolved when the fixture is stable after all async tasks started by an event handler are complete.
Closes #8265