Skip to content

fix: auto-spy standalone inject() services (#9397)#13310

Open
satanTime wants to merge 1 commit intohelp-me-mom:mainfrom
satanTime:issues/9397
Open

fix: auto-spy standalone inject() services (#9397)#13310
satanTime wants to merge 1 commit intohelp-me-mom:mainfrom
satanTime:issues/9397

Conversation

@satanTime
Copy link
Copy Markdown
Member

Summary

  • auto-spy root-provided services resolved through standalone component inject() properties
  • add focused regressions for inject(), constructor injection, and non-injected lookalike guards
  • validate the issue against Angular 14 and scoped root coverage paths

Closes #9397

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9eed052) to head (4dff48e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main    #13310   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          228       228           
  Lines         4168      4193   +25     
  Branches      1187      1192    +5     
=========================================
+ Hits          4168      4193   +25     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@satanTime satanTime changed the title fix: auto-spy standalone inject() services #9397 fix: auto-spy standalone inject() services (#9397) Mar 15, 2026
Copy link
Copy Markdown
Member Author

@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.

Two review findings from a local pass.

(componentCtor.tpl && isNgDef(template, 'p'))
) {
renderDeclaration(fixture, template, params);
autoSpyStandaloneInjectProperties(template, fixture.point.componentInstance);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

autoSpyStandaloneInjectProperties(...) runs only after the first fixture.detectChanges(). That means any inject()-backed service call made during ngOnInit, an effect triggered on the first render, or other first-pass lifecycle work still hits the original method and will never be counted by ngMocks.autoSpy(). The new regression test only exercises calls made after MockRender(), so this path stays uncovered.

const autoSpyStandaloneInjectProperties = (template: any, instance: any): void => {
if (
!instance ||
!isNgDef(template, 'c') ||
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This helper is gated to components only via isNgDef(template, 'c'), but this render path also serves standalone directives, and the pipe wrapper case reaches the same area too. A standalone directive or pipe that uses inject() still appears to bypass auto-spy support, so either the guard needs widening or the narrower scope should be documented and covered explicitly.

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: inject function can not be mocked

1 participant