Remove unnecessary zoning on event handlers that interferes with testing #181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The way the zone used for component lifecycle methods is determined is unpredictable: whatever zone the first
registerComponent
is called in is used, and all subsequent components will also use that zone as well.This means that if the first component is rendered in a
test
block, all other lifecycle methods will be run in that test's zone, resulting in output that:Also, as a result, any event handlers added to a ReactElement within a component also had the same output issues.
The way the zone used for event handlers is determined gets in the way of testing: the zone in which the ReactElement with the event handler is used.
This results in errors such as the following when wrapping
expectAsync
in event handlers or usingexpect
in them, since they're executed in the root zone as opposed to the current test's zone.This happens quite commonly when testing w_flux actions, or custom event-based prop callbacks.
Solution
Always use the root zone to run component lifecycle methods, since that's what it should be most of the time.I tried this out, and unfortunately it seems that many tests depend on this zoning, and actually run
expect
in other tests' zones... 😢 We'll have to revisit this.Testing
expectAsync
no longer needs a zone-bound callback with these changes pulled in