Skip to content

Generated app component does not respect style guide #30335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
jnizet opened this issue May 17, 2025 · 0 comments · Fixed by #30344
Closed
1 task

Generated app component does not respect style guide #30335

jnizet opened this issue May 17, 2025 · 0 comments · Fixed by #30344
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity1: confusing type: bug/fix

Comments

@jnizet
Copy link
Contributor

jnizet commented May 17, 2025

Command

new

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When generating a new project with version 20 of the CLI, the following component class is generated:

export class App {
  title = 'foov20';
}

This violates the new style guide, which says:

Use protected on class members that are only used by a component's template

If we add the protected modifier though, the generated spec doesn't compile anymore. Indeed, the spec file contains these three tests:

  it('should create the app', () => {
    const fixture = TestBed.createComponent(App);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });

  it(`should have the 'foov20' title`, () => {
    const fixture = TestBed.createComponent(App);
    const app = fixture.componentInstance;
    expect(app.title).toEqual('foov20');
  });

  it('should render title', () => {
    const fixture = TestBed.createComponent(App);
    fixture.detectChanges();
    const compiled = fixture.nativeElement as HTMLElement;
    expect(compiled.querySelector('h1')?.textContent).toContain('Hello, foov20');
  });

but I would argue that

  • the first one isn't really useful (if it fails, the other two tests also fail)
  • the second one (which is the one that does not compile anymore) isn't really useful either: it tests the internal implementation of the component rather than testing its behavior, and the third one is sufficient.

Minimal Reproduction

npx @angular/cli@next new foov20

Exception or Error


Your Environment

Angular CLI: 20.0.0-rc.2
Node: 20.12.2
Package Manager: npm 10.5.0
OS: darwin x64

Angular: 20.0.0-rc.1
... common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.2000.0-rc.2
@angular-devkit/core         20.0.0-rc.2
@angular-devkit/schematics   20.0.0-rc.2
@angular/build               20.0.0-rc.2
@angular/cli                 20.0.0-rc.2
@schematics/angular          20.0.0-rc.2
rxjs                         7.8.2
typescript                   5.8.3
zone.js                      0.15.0

Anything else relevant?

No response

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity1: confusing area: @schematics/angular labels May 19, 2025
@alan-agius4 alan-agius4 linked a pull request May 19, 2025 that will close this issue
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity1: confusing type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants