Skip to content

fix(@schematics/angular): include the type separator in the class spec import - #34486

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
thekhegay:class-spec-type-separator
Oct 27, 2026
Merged

alan-agius4 merged 1 commit into
angular:mainfrom
thekhegay:class-spec-type-separator

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

ng g class user --type=model writes user.model.spec.ts with import { User } from './usermodel', so generated spec fails with TS2307 (checked on 22.2.3)
Since 322f6ec class schematic no longer prefixes type with dot, dot lives only in file name __name@dasherize__.__type__.spec.ts, while spec template still imports './<%= dasherize(name) %><%= type %>'
skipTests is false by dafault and every class generated with --type gets this spec

What is the new behavior?

Template adds dot only when type is set, so import becomes './user.model' and without --type it stays './user'
New case in class/index_spec.ts fails on main

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Raw type on purpose: class file name token is __type__ without @dasherize, so import has to match it
Service and directive templates dasherize both sides

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Angular class schematic template for spec files to correctly format the import path when a type option is provided, ensuring a dot is prepended to the type name (e.g., './foo.model' instead of './foomodel'). It also adds a corresponding unit test to verify this behavior. There are no review comments to address.

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Oct 27, 2026
…c import

class spec template imports `'./<name><type>'`, and `type` reaches it without leading dot since class schematic moved to `generateFromFiles`
so `ng g class user --type=model` writes `user.model.spec.ts` with `import { User } from './usermodel'` and generated spec does not compile
template now adds dot only when type is set, matching `__type__` file name token
@alan-agius4
alan-agius4 force-pushed the class-spec-type-separator branch from 9d05cef to 718cb5f Compare October 27, 2026 15:38

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks

@alan-agius4
alan-agius4 merged commit 4a59335 into angular:main Oct 27, 2026
39 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants