cleanup(angular): add unit tests coverage for generating a minimal application (#15693)

This commit is contained in:
Leosvel Pérez Espinosa 2023-03-20 16:00:37 +00:00 committed by GitHub
parent e9b5181696
commit fa8ede1b4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 250 additions and 2 deletions

View File

@ -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`] = `
"<h1>Welcome plain</h1> <router-outlet></router-outlet>
"
`;
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`] = `
"<h1>Welcome plain</h1>
"
`;
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`] = `
"<h1>Welcome plain</h1> <router-outlet></router-outlet>
"
`;
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`] = `
"<h1>Welcome plain</h1>
"
`;
exports[`app --standalone should generate a standalone app correctly with routing 1`] = `
"import { bootstrapApplication } from '@angular/platform-browser';
import {

View File

@ -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();
});
});
});