Skip to content

Template coverage does not register for components whose spec calls TestBed.overrideComponent #7458

Open

Description

@aglinxinyuan

Task Summary

Six component templates report 0% coverage despite having substantial, passing specs, and adding tests to them does not change the number. Together they account for roughly 230 uncovered lines that no amount of test writing can reach.

Template Spec size Reported
hub-workflow-detail.component.html 442-line spec, 7 detectChanges 0%
user-project.component.html 262-line spec 0%
search.component.html 242-line spec 0%
workspace.component.html — 0%
hub-search-result.component.html — 0%
search-results.component.html — 75.8% (partial)

The common factor is TestBed.overrideComponent. Across the repo, templates whose spec calls it average 18% coverage with 6 of 8 at zero; templates whose spec does not average 76.7%, with only 2 of 73 at zero. Every one of these specs uses the additive remove/add: { imports } form to swap heavyweight child components for stubs — they do not override the template itself, so the real template genuinely renders and is genuinely exercised. It simply is not attributed.

Two counterexamples (search-results, operator-property-edit-frame) also call overrideComponent and do report coverage, so overrideComponent alone is not a sufficient explanation and the precise trigger is still unidentified.

Why this matters

These files look like the largest remaining coverage gaps in the frontend, so they attract effort that cannot pay off. Two separate coverage sweeps ranked hub-workflow-detail (46 lines) and user-project (38 lines) near the top of the backlog before the pattern was spotted. Anyone working from the Codecov file list will keep rediscovering them.

Suggested next steps

  • Confirm the mechanism — most likely the component recompilation overrideComponent triggers produces a template with a different identity than the one the coverage remapper knows about.
  • If it cannot be fixed, exclude these templates from the coverage denominator so the reported figure reflects what is actually testable, and note the reason.
  • Either way, record it somewhere discoverable so the next person ranking targets does not spend the effort again.

Task Type

  • Refactor / Cleanup
  • DevOps / Deployment / CI
  • Testing / QA
  • Documentation
  • Performance
  • Other

Activity

  1. added theissue type on Aug 9, 2026
  2. aglinxinyuan commented on Aug 11, 2026

    @aglinxinyuan
    ContributorAuthor

    Root cause found, and measured rather than inferred.

    The mechanism. TestBed.overrideComponent makes Angular re-JIT the component from its retained decorator metadata (pendingComponents → compileComponent → jitExpression). The re-compiled template function carries no source map back to the .component.html, so every binding still executes and none of it is attributed. That is why the affected components show a healthy .ts next to a .html at exactly zero — agent-panel.component.ts is 98.5% with 0 of 133 lines missed while agent-panel.component.html is 0/49. Nothing but attribution loss produces that pair.

    All eight zero-coverage templates are now accounted for, by correlating every one of the 98 .html files in the live Codecov report:

    Template Lines Cause
    agent-panel 49 overridden in its only rendering spec
    hub-workflow-detail 46 same
    user-project 38 same
    search 35 same
    workspace 28 same
    hub-search-result 25 same
    ui-udf-parameters — spec never uses TestBed (new UiUdfParametersComponent())
    collab-wrapper 67 no spec (and #7351 deletes it)

    The two overridden specs whose templates are covered confirm the mechanism from the other direction: search-results.component.html (75.8%) and operator-property-edit-frame.component.html (68.2%) each have a sibling spec that renders the real component un-overridden.

    The remedy works. #7535 applies it to hub-workflow-detail:

    Before After
    lines 0/46 (0.0%) 45/46 (97.8%)
    branches — 3/3

    Three tests, and the existing 32 are untouched — the new block keeps its own TestBed so those tests keep their mocked WorkflowActionService and the ten assertions they make on it. Wholesale de-stubbing would mean rewriting those ten, which is a worse trade than adding a render block.

    One thing that should change regardless of whether anyone picks up the remaining five. frontend/.eslintrc.json currently prescribes the pattern that causes this, in three separate messages — the NO_ERRORS_SCHEMA rule and both overrideComponent rules all tell authors to "stub it via overrideComponent({ remove: { imports: [Real] }, add: { imports: [Stub] } })". The set: { template } message is right that substituting a template zeroes coverage, but the additive remove/add form it recommends instead does the same thing, for the same reason. Accurate guidance would be: any override zeroes the template's coverage, so prefer expanding the child's service stubs so the real child can instantiate, and if a child genuinely cannot be, add a sibling block that renders the real component.

    Happy to send that eslintrc wording as its own small PR if that is wanted — I kept it out of #7535 so the test change stays spec-only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions