fix(core): warn when overrideComponent is called with layout/imports/schema overrides in AOT mode#69730
fix(core): warn when overrideComponent is called with layout/imports/schema overrides in AOT mode#69730clydin wants to merge 1 commit into
Conversation
476ced6 to
6800b62
Compare
| ); | ||
| }); | ||
|
|
||
| it('should NOT warn when overrideComponent is called on an AOT component with safe overrides (like providers)', () => { |
There was a problem hiding this comment.
Consider: Should we also test not warning on a JIT component?
| console.warn( | ||
| `[Angular] WARNING: 'TestBed.overrideComponent' was called on '${component.name}' with template/import/schema overrides in AOT mode. ` + | ||
| `This is not fully supported and may cause NG0304/NG0303 element resolution errors. \n` + | ||
| `👉 Workaround: Disable AOT compilation in the build configuration used for tests (e.g. set 'aot: false' or equivalent).`, |
There was a problem hiding this comment.
Consider: Should we point out @Component({jit: true}) as an option? You probably don't want that for production components, but might be useful for test components without opting-out the whole test suite into JIT? Maybe this is too easy to misuse to be worth calling out, but figured I'd mention it?
There was a problem hiding this comment.
Perhaps we could also create an entry in the documentation for this case?
…schema overrides in AOT mode TestBed.overrideComponent relies on runtime decorator metadata to dynamically recompile components. When tests are compiled in AOT mode, decorator metadata is compiled away, meaning template or imports overrides can fail silently or cause confusing NG0304/NG0303 errors. To improve developer experience, this adds a runtime warning when TestBed.overrideComponent is called on an AOT-compiled component with template, import, schema, or layout overrides in AOT mode. A warning is printed to the console suggesting to disable AOT (aot: false) in the test build configuration as a workaround. Overriding provider/viewProvider metadata remains fully supported without warnings.
6800b62 to
0de2838
Compare
|
Unless |
TestBed.overrideComponent relies on runtime decorator metadata to dynamically recompile components. When tests are compiled in AOT mode, decorator metadata is compiled away, meaning template or imports overrides can fail silently or cause confusing NG0304/NG0303 errors.
To improve developer experience, this adds a runtime warning when TestBed.overrideComponent is called on an AOT-compiled component with template, import, schema, or layout overrides in AOT mode. A warning is printed to the console suggesting to disable AOT (aot: false) in the test build configuration as a workaround.
Overriding provider/viewProvider metadata remains fully supported without warnings.