chore(frontend): clean up template-override anti-pattern in component specs#5189
Merged
Yicong-Huang merged 3 commits intoMay 24, 2026
Merged
Conversation
aglinxinyuan
approved these changes
May 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5189 +/- ##
============================================
+ Coverage 44.54% 45.26% +0.71%
Complexity 2217 2217
============================================
Files 1042 1042
Lines 39989 39989
Branches 4260 4260
============================================
+ Hits 17814 18101 +287
+ Misses 21059 20768 -291
- Partials 1116 1120 +4
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…pattern 8
Revise TESTING.md to describe the right way to handle child components
in a standalone-component spec, based on actual texera experience:
- Anti-pattern 2 (NO_ERRORS_SCHEMA): explain why Angular 19 standalone
parents rarely need the schema; the import graph is pulled in
transitively. The typical failure that drives people to add it is a
child's ngOnInit reading a service method that the stub doesn't have
— extend the service stub, don't reach for the schema.
- Anti-pattern 3 (template substitution): generalise from "empty
template" to any template substitution, including stub markup. Both
pin the real .component.html to 0% coverage.
- New Recipe F: the legitimate way to stub a child component when it
truly can't be instantiated — additive override via remove + add.
- New anti-pattern 8: the `set: { imports: [], schemas: [...] }` form
is unreliable (angular/angular#48432) and silences real errors. Use
the additive remove/add form instead.
Closes apache#5188 (docs portion).
…mponent specs Drop the test-time template substitutions, schema escape hatches, and "empty imports + CUSTOM_ELEMENTS_SCHEMA" overrides from the specs that carried them. Each affected `.component.html` now renders its real template under jsdom, lifting coverage off 0%. In the cases where a child component's ngOnInit relied on a service method the stub didn't have, the fix is to extend the stub — not to re-introduce the schema. Two specs (operator-property-edit-frame and workspace) keep the old shape behind targeted eslint-disable comments with TODO references; they need a more thorough redesign to migrate cleanly.
…ESLint
Add an `*.spec.ts` override to `.eslintrc.json` so the patterns the
previous commits just cleared can't grow back:
- `no-restricted-imports` blocks `NO_ERRORS_SCHEMA` from `@angular/core`.
- `no-restricted-syntax` flags any `template` or `imports` key inside
`overrideComponent({ set: ... })` — empty string, stub markup, or
empty array all violate.
The message on each rule points at the right replacement (extend the
service stub, or use the additive remove + add form). See
`frontend/TESTING.md` anti-patterns 2, 3, and 8.
5a9bc56 to
5233462
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this PR?
Three coordinated passes against the "specs that replace the parent template at test time" anti-pattern:
frontend/TESTING.md: anti-patterns 2 and 3 are rewritten to describe what actually goes wrong (the real.component.htmlnever executes, so v8 coverage stays at 0%), and a new Recipe F + anti-pattern 8 cover the right way to handle a heavy child component when one truly cannot be instantiated — additiveoverrideComponent({ remove, add })with a minimal stub child.template: "", a stub-markup template substitute,NO_ERRORS_SCHEMA, or the broaderset: { imports: [], schemas: [...] }override is migrated to render the real template. Two specs (Formly-driven and the full WorkspaceComponent) keep the old shape behind a scopedeslint-disablewith a TODO; both need a more thorough redesign that isn't in scope here.*.spec.tsoverride in.eslintrc.jsonblocks the patterns going forward —NO_ERRORS_SCHEMAimports from@angular/core, anytemplateorimportskey insideoverrideComponent({ set: ... }). Each rule's message points at the right replacement.Any related issues, documentation, discussions?
Closes #5188. Builds on the testing guide introduced in #5170 and the lint-guardrail pattern from #5185.
How was this PR tested?
yarn ng test --watch=false --include=…over the touched specs runs 13 files / 108 tests, all green.yarn lintandyarn format:ciboth clean. The three template files that originally pinned at 0% —preset-wrapper.component.html,operator-menu.component.html,menu.component.html— now report 44 / 79 / 59% line coverage under the new shape.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7