mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 05:52:41 +08:00
fix(@schematics/angular): remove compileComponents from component test schematic
`compileComponents` is not necessary when using the CLI (as the templates are inlined) and just adds boilerplate code. So we can remove it from the test schematic and make it independent from `async/await` (only place we would have it in the CLI generated code, and in most Angular apps).
This commit is contained in:
parent
ba4414b2cf
commit
202e9a50f6
@ -23,7 +23,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent
|
AppComponent
|
||||||
@ -40,7 +40,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
'./src/app/app.component.ts': `
|
'./src/app/app.component.ts': `
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
template: '<p *ngFor="let asset of assets">{{ asset.content }}</p>'
|
template: '<p *ngFor="let asset of assets">{{ asset.content }}</p>'
|
||||||
@ -62,19 +62,13 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
imports: [HttpClientModule],
|
||||||
imports: [
|
declarations: [AppComponent]
|
||||||
HttpClientModule
|
}));
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
AppComponent
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.debugElement.componentInstance;
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
@ -29,15 +29,9 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
declarations: [AppComponent]
|
||||||
imports: [
|
}));
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
AppComponent
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not contain text that is hidden via css', () => {
|
it('should not contain text that is hidden via css', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
@ -97,16 +91,10 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
imports: [HttpClientModule],
|
||||||
imports: [
|
declarations: [AppComponent]
|
||||||
HttpClientModule
|
}));
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
AppComponent
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.debugElement.componentInstance;
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
@ -30,7 +30,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
}`,
|
}`,
|
||||||
'src/app/app.worker.ts': `
|
'src/app/app.worker.ts': `
|
||||||
/// <reference lib="webworker" />
|
/// <reference lib="webworker" />
|
||||||
|
|
||||||
const prefix: string = 'Data: ';
|
const prefix: string = 'Data: ';
|
||||||
addEventListener('message', ({ data }) => {
|
addEventListener('message', ({ data }) => {
|
||||||
postMessage(prefix + data);
|
postMessage(prefix + data);
|
||||||
@ -52,13 +52,9 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
declarations: [AppComponent]
|
||||||
declarations: [
|
}));
|
||||||
AppComponent
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('worker should be defined', () => {
|
it('worker should be defined', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
@ -82,13 +78,9 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
declarations: [AppComponent]
|
||||||
declarations: [
|
}));
|
||||||
AppComponent
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('worker should throw', () => {
|
it('worker should throw', () => {
|
||||||
expect(() => TestBed.createComponent(AppComponent))
|
expect(() => TestBed.createComponent(AppComponent))
|
||||||
|
@ -9,11 +9,9 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
declarations: [AppComponent],
|
||||||
declarations: [AppComponent],
|
}));
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.debugElement.componentInstance;
|
const app = fixture.debugElement.componentInstance;
|
||||||
|
@ -14,12 +14,9 @@ describe('LibComponent', () => {
|
|||||||
let component: LibComponent;
|
let component: LibComponent;
|
||||||
let fixture: ComponentFixture<LibComponent>;
|
let fixture: ComponentFixture<LibComponent>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
declarations: [LibComponent]
|
||||||
declarations: [ LibComponent ]
|
}));
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(LibComponent);
|
fixture = TestBed.createComponent(LibComponent);
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
await TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [AppComponent],
|
declarations: [AppComponent],
|
||||||
}).compileComponents();
|
});
|
||||||
});
|
});
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
@ -3,16 +3,10 @@ import { RouterTestingModule } from '@angular/router/testing';<% } %>
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({<% if (routing) { %>
|
||||||
await TestBed.configureTestingModule({<% if (routing) { %>
|
imports: [RouterTestingModule],<% } %>
|
||||||
imports: [
|
declarations: [AppComponent]
|
||||||
RouterTestingModule
|
}));
|
||||||
],<% } %>
|
|
||||||
declarations: [
|
|
||||||
AppComponent
|
|
||||||
],
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
@ -2,11 +2,9 @@ import { TestBed } from '@angular/core/testing';
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
imports: [AppComponent]
|
||||||
imports: [AppComponent],
|
}));
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
@ -6,12 +6,10 @@ describe('<%= classify(name) %><%= classify(type) %>', () => {
|
|||||||
let component: <%= classify(name) %><%= classify(type) %>;
|
let component: <%= classify(name) %><%= classify(type) %>;
|
||||||
let fixture: ComponentFixture<<%= classify(name) %><%= classify(type) %>>;
|
let fixture: ComponentFixture<<%= classify(name) %><%= classify(type) %>>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
await TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
<%= standalone ? 'imports' : 'declarations' %>: [ <%= classify(name) %><%= classify(type) %> ]
|
<%= standalone ? 'imports' : 'declarations' %>: [<%= classify(name) %><%= classify(type) %>]
|
||||||
})
|
});
|
||||||
.compileComponents();
|
|
||||||
|
|
||||||
fixture = TestBed.createComponent(<%= classify(name) %><%= classify(type) %>);
|
fixture = TestBed.createComponent(<%= classify(name) %><%= classify(type) %>);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@ -431,7 +431,7 @@ describe('Component Schematic', () => {
|
|||||||
const options = { ...defaultOptions, standalone: true };
|
const options = { ...defaultOptions, standalone: true };
|
||||||
const tree = await schematicRunner.runSchematic('component', options, appTree);
|
const tree = await schematicRunner.runSchematic('component', options, appTree);
|
||||||
const testContent = tree.readContent('/projects/bar/src/app/foo/foo.component.spec.ts');
|
const testContent = tree.readContent('/projects/bar/src/app/foo/foo.component.spec.ts');
|
||||||
expect(testContent).toContain('imports: [ FooComponent ]');
|
expect(testContent).toContain('imports: [FooComponent]');
|
||||||
expect(testContent).not.toContain('declarations');
|
expect(testContent).not.toContain('declarations');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,16 +3,10 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
imports: [RouterTestingModule],
|
||||||
imports: [
|
declarations: [AppComponent]
|
||||||
RouterTestingModule
|
}));
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
AppComponent
|
|
||||||
],
|
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
@ -18,12 +18,10 @@ export default async function () {
|
|||||||
jasmine.clock().uninstall();
|
jasmine.clock().uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
imports: [RouterTestingModule],
|
||||||
imports: [RouterTestingModule],
|
declarations: [AppComponent],
|
||||||
declarations: [AppComponent],
|
}));
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
@ -30,11 +30,9 @@ export default async function () {
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
await TestBed.configureTestingModule({
|
declarations: [AppComponent]
|
||||||
declarations: [ AppComponent ]
|
}));
|
||||||
}).compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should have access to string-script.js', () => {
|
it('should have access to string-script.js', () => {
|
||||||
let app = TestBed.createComponent(AppComponent).debugElement.componentInstance;
|
let app = TestBed.createComponent(AppComponent).debugElement.componentInstance;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user