diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index c5b511acee..a620a9525a 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -1,6 +1,66 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`app --minimal should skip Nx specific \`nx-welcome.component.ts\` file creation 1`] = ` +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps with routing 1`] = ` +"import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { RouterModule } from '@angular/router'; +import { AppComponent } from './app.component'; +import { appRoutes } from './app.routes'; + +@NgModule({ + declarations: [AppComponent], + imports: [ + BrowserModule, + RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' }), + ], + providers: [], + bootstrap: [AppComponent], +}) +export class AppModule {} +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps with routing 2`] = ` +"import { Component } from '@angular/core'; + +@Component({ + selector: 'proj-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'], +}) +export class AppComponent {} +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps with routing 3`] = ` +"import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { RouterTestingModule } from '@angular/router/testing'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [RouterTestingModule], + declarations: [AppComponent] + }).compileComponents(); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain('Welcome plain'); + }); +}); +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps with routing 4`] = ` +"

Welcome plain

+" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps without routing 1`] = ` "import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; @@ -17,6 +77,127 @@ export class AppModule {} " `; +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps without routing 2`] = ` +"import { Component } from '@angular/core'; + +@Component({ + selector: 'proj-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'], +}) +export class AppComponent {} +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps without routing 3`] = ` +"import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [], + declarations: [AppComponent] + }).compileComponents(); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain('Welcome plain'); + }); +}); +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for non-standalone apps without routing 4`] = ` +"

Welcome plain

+" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for standalone apps with routing 1`] = ` +"import { Component } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +@Component({ + standalone: true, + imports: [RouterModule], + selector: 'proj-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'], +}) +export class AppComponent {} +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for standalone apps with routing 2`] = ` +"import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { RouterTestingModule } from '@angular/router/testing'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent, RouterTestingModule], + }).compileComponents(); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain('Welcome plain'); + }); +}); +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for standalone apps with routing 3`] = ` +"

Welcome plain

+" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for standalone apps without routing 1`] = ` +"import { Component } from '@angular/core'; + +@Component({ + standalone: true, + imports: [], + selector: 'proj-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'], +}) +export class AppComponent {} +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for standalone apps without routing 2`] = ` +"import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent], + }).compileComponents(); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain('Welcome plain'); + }); +}); +" +`; + +exports[`app --minimal should skip "nx-welcome.component.ts" file and references for standalone apps without routing 3`] = ` +"

Welcome plain

+" +`; + exports[`app --standalone should generate a standalone app correctly with routing 1`] = ` "import { bootstrapApplication } from '@angular/platform-browser'; import { diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index af5d55687f..2e099d6245 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -886,15 +886,82 @@ describe('app', () => { }); describe('--minimal', () => { - it('should skip Nx specific `nx-welcome.component.ts` file creation', async () => { + it('should skip "nx-welcome.component.ts" file and references for non-standalone apps without routing', async () => { await generateApp(appTree, 'plain', { minimal: true }); + expect( + appTree.exists('apps/plain/src/app/nx-welcome.component.ts') + ).toBeFalsy(); expect( appTree.read('apps/plain/src/app/app.module.ts', 'utf-8') ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.spec.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.html', 'utf-8') + ).toMatchSnapshot(); + }); + + it('should skip "nx-welcome.component.ts" file and references for non-standalone apps with routing', async () => { + await generateApp(appTree, 'plain', { minimal: true, routing: true }); + expect( appTree.exists('apps/plain/src/app/nx-welcome.component.ts') ).toBeFalsy(); + expect( + appTree.read('apps/plain/src/app/app.module.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.spec.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.html', 'utf-8') + ).toMatchSnapshot(); + }); + + it('should skip "nx-welcome.component.ts" file and references for standalone apps without routing', async () => { + await generateApp(appTree, 'plain', { minimal: true, standalone: true }); + + expect( + appTree.exists('apps/plain/src/app/nx-welcome.component.ts') + ).toBeFalsy(); + expect( + appTree.read('apps/plain/src/app/app.component.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.spec.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.html', 'utf-8') + ).toMatchSnapshot(); + }); + + it('should skip "nx-welcome.component.ts" file and references for standalone apps with routing', async () => { + await generateApp(appTree, 'plain', { + minimal: true, + standalone: true, + routing: true, + }); + + expect( + appTree.exists('apps/plain/src/app/nx-welcome.component.ts') + ).toBeFalsy(); + expect( + appTree.read('apps/plain/src/app/app.component.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.spec.ts', 'utf-8') + ).toMatchSnapshot(); + expect( + appTree.read('apps/plain/src/app/app.component.html', 'utf-8') + ).toMatchSnapshot(); }); }); });