-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Labels
area: @schematics/angularfreq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarelyseverity1: confusingtype: bug/fix
Description
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
Metadata
Metadata
Assignees
Labels
area: @schematics/angularfreq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarelyseverity1: confusingtype: bug/fix