-
-
Notifications
You must be signed in to change notification settings - Fork 120
Use reflectComponentType as a Fallback to Detect Signals
#11909
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
Merged
satanTime
merged 6 commits into
help-me-mom:master
from
Watercycle:feature/angular-19-signal-inputs-v3
Dec 11, 2025
+113
−19
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
807f161
feat: partial(?) signal support via parseReflectComponentType
Watercycle cc586bc
feat: make sure it's compatible with older compiler versions
Watercycle fe60aaf
feat: Make Webpack not dig into reflectComponentType
Watercycle 3e6ae38
feat: Remove unnecessary conditional branches
Watercycle b871a85
feat: Add reflectComponentType testing shim
Watercycle 754e4ff
feat: Skip `reflectComponentType` from build tool processing
Watercycle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
libs/ng-mocks/src/lib/common/func.reflect-component-type.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import funcGetGlobal from './func.get-global'; | ||
| import funcReflectComponentType from './func.reflect-component-type'; | ||
|
|
||
| describe('funcReflectComponentType', () => { | ||
| let global: any; | ||
|
|
||
| beforeEach(() => { | ||
| global = funcGetGlobal(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete global.__ngMocksReflectComponentType; | ||
| }); | ||
|
|
||
| it('returns undefined when API does not exist', () => { | ||
| // Simulate Angular 13 - where reflectComponentType doesn't exist | ||
| global.__ngMocksReflectComponentType = false; | ||
|
|
||
| const result = funcReflectComponentType({ test: 'component' }); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns result when API exists and works', () => { | ||
| const mockMirror = { inputs: [], outputs: [] }; | ||
| global.__ngMocksReflectComponentType = jasmine | ||
| .createSpy('mockReflectComponentType') | ||
| .and.returnValue(mockMirror); | ||
|
|
||
| const result = funcReflectComponentType({ test: 'component' }); | ||
| expect(result).toBe(mockMirror); | ||
| }); | ||
| }); |
22 changes: 22 additions & 0 deletions
22
libs/ng-mocks/src/lib/common/func.reflect-component-type.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as angularCore from '@angular/core'; | ||
|
|
||
| import funcGetGlobal from './func.get-global'; | ||
|
|
||
| /** | ||
| * Helper function to safely access Angular's reflectComponentType API. | ||
| * This API is available in Angular 14+ and is used for runtime reflection | ||
| * of component metadata, particularly for signal inputs/outputs. | ||
| */ | ||
| export default (def: any): any => { | ||
| const global = funcGetGlobal(); | ||
|
|
||
| // Use test override if present, otherwise use real API | ||
| const reflectApi = 'reflect' + 'ComponentType'; // Avoid build tool processing | ||
| const reflectComponentType = global.__ngMocksReflectComponentType ?? (angularCore as any)[reflectApi]; | ||
|
|
||
| if (!reflectComponentType) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return reflectComponentType(def); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.