| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
TestBed.overrideComponent previously caused JIT recompilation to overwrite a component's original ChangeDetectionStrategy. This ensures the component's existing ChangeDetectionStrategy is preserved when metadata overrides are applied.
| Back | FazBrowse Home | New Git URL |
TestBed.overrideComponent previously caused JIT recompilation to overwrite a component's original ChangeDetectionStrategy. This ensures the component's existing ChangeDetectionStrategy is preserved when metadata overrides are applied.
Disclaimer: Note that the root cause analysis of the bug and the solution were identified with the help of AI. I implemented the change, tests, and ran it against our codebase. The problem is in my opinion very much genuine but a different solution may be more appropriate.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When a component without explicit changeDetection strategy is overridden with TestBed.overrideComponent, the change detection strategy changes from OnPush (default) to Eager. This causes a mismatch between prod and test component behavior.
AI's explanation: When TestBed.overrideComponent is called on a component, the component is added to TestBed's pendingComponents queue, forcing runtime JIT recompilation (compileTypesSync()). During this JIT recompilation, TestBed reconstructs the component metadata. Previously, the metadata decorator resolution defaulted changeDetection to ChangeDetectionStrategy.Eager, overwriting the component's existing (ɵcmp) Change Detection Strategy.
As a result, an overridden component whose pre-compiled definition used ChangeDetectionStrategy.OnPush would unexpectedly run with ChangeDetectionStrategy.Default (Eager) in tests.
Issue Number: N/A
What is the new behavior?
When compiling component overrides in TestBed, the implicit ChangeDetectionStrategy (onPush property on the pre-compiled ɵcmp definition) is preserved.
Does this PR introduce a breaking change?
Note on potential behavioral impact: While this is a bugfix restoring expected component behavior during testing, it could affect existing tests if consumers unknowingly relied on TestBed.overrideComponent silently reverting an OnPush component to Eager (Default) change detection. No such issue was found across our codebase.
Other information