fix: auto-spy standalone inject() services (#9397)#13310
fix: auto-spy standalone inject() services (#9397)#13310satanTime wants to merge 1 commit intohelp-me-mom:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
satanTime
left a comment
There was a problem hiding this comment.
Two review findings from a local pass.
| (componentCtor.tpl && isNgDef(template, 'p')) | ||
| ) { | ||
| renderDeclaration(fixture, template, params); | ||
| autoSpyStandaloneInjectProperties(template, fixture.point.componentInstance); |
There was a problem hiding this comment.
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') || |
There was a problem hiding this comment.
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.
Summary
Closes #9397