Skip to content
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

Remove ViewChild from metadata #8771

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

c-harding
Copy link

ViewChild will always be null, and so there is no point in mocking it.
viewChild.required throws an error in mocked components without this
change.

Fixes GH-8634

ViewChild will always be null, and so there is no point in mocking it.
viewChild.required throws an error in mocked components without this
change.

Fixes help-me-momGH-8634
Copy link

codecov bot commented Apr 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (78b1979) to head (4421a1c).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #8771   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          227       227           
  Lines         4935      4936    +1     
  Branches      1147      1148    +1     
=========================================
+ Hits          4935      4936    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@satanTime satanTime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there.

Thank you for contribution, but it's a breaking change which affects other angular versions. Should be fixed without breaking anything.

@c-harding
Copy link
Author

Hi @satanTime, what’s the effect for other versions? Only __prop_metadata__ is affected, which is not a documented property. Additionally, viewChild would always be falsy for mocked components anyway, because mocked components do not have any of their own elements as children.

@satanTime
Copy link
Member

ng-mocks uses many undocumented and monkey patched things.

For a proper PR, you need to provide a proper test which demonstrates the issue and its fix.

Here, I see that mocks which provide own empty views now will return nulls instead of objects, so tests which relied on these empty views will fail despite no change in the code, only due to the update of ng-mocks.

That's what should be avoided, so what worked before should still work afterwards.

@dmitry-stepanenko
Copy link

dmitry-stepanenko commented May 24, 2024

@satanTime signal-based queries have isSignal: true property set. WDYT if we would modify the condition as follows

diff --git a/libs/ng-mocks/src/lib/common/decorate.queries.ts b/libs/ng-mocks/src/lib/common/decorate.queries.ts
index 860983934..f69eb1423 100644
--- a/libs/ng-mocks/src/lib/common/decorate.queries.ts
+++ b/libs/ng-mocks/src/lib/common/decorate.queries.ts
@@ -26,8 +26,11 @@ const generateFinalQueries = (queries: {
   const scanKeys: string[] = [];
 
   for (const key of Object.keys(queries)) {
-    const query: Query & { ngMetadataName?: string } = queries[key];
-    final.push([key, query]);
+    const query: Query & { ngMetadataName?: string; isSignal?: boolean } = queries[key];
+    const isSignalBasedQuery = query.isViewQuery && query.isSignal;
+    if (!isSignalBasedQuery) {
+      final.push([key, query]);
+    }
 
     if (!query.isViewQuery && !isInternalKey(key)) {
       scanKeys.push(key);

That way it should not be considered as a regression for any existing cases while still allowing us to move forward

@c-harding
Copy link
Author

@dmitry-stepanenko that sounds promising! I’ve given you write access to this repo, so you’re welcome to edit the PR directly

@dmitry-stepanenko
Copy link

awesome, thanks @c-harding. I'll update the branch shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Incompatibility of MockComponent with new viewChild signal function
3 participants