From a7326bf1b75bc3d772327949f4144a84e041c8cb Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 13 Jul 2020 16:09:56 -0400 Subject: [PATCH 1/2] fix(@schematics/angular): remove async test helper function from component schematic --- .../other-files/app.component.spec.ts.template | 8 ++++---- ...__name@dasherize__.__type@dasherize__.spec.ts.template | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/schematics/angular/application/other-files/app.component.spec.ts.template b/packages/schematics/angular/application/other-files/app.component.spec.ts.template index 08513f442052..fcdf822fb55b 100644 --- a/packages/schematics/angular/application/other-files/app.component.spec.ts.template +++ b/packages/schematics/angular/application/other-files/app.component.spec.ts.template @@ -1,10 +1,10 @@ -import { TestBed, async } from '@angular/core/testing';<% if (routing) { %> +import { TestBed } from '@angular/core/testing';<% if (routing) { %> import { RouterTestingModule } from '@angular/router/testing';<% } %> import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({<% if (routing) { %> + beforeEach(async () => { + await TestBed.configureTestingModule({<% if (routing) { %> imports: [ RouterTestingModule ],<% } %> @@ -12,7 +12,7 @@ describe('AppComponent', () => { AppComponent ], }).compileComponents(); - })); + }); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); diff --git a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template index 504f6c091efc..66f886292908 100644 --- a/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template +++ b/packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.spec.ts.template @@ -1,4 +1,4 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { <%= classify(name) %><%= classify(type) %> } from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>'; @@ -6,12 +6,12 @@ describe('<%= classify(name) %><%= classify(type) %>', () => { let component: <%= classify(name) %><%= classify(type) %>; let fixture: ComponentFixture<<%= classify(name) %><%= classify(type) %>>; - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ <%= classify(name) %><%= classify(type) %> ] }) .compileComponents(); - })); + }); beforeEach(() => { fixture = TestBed.createComponent(<%= classify(name) %><%= classify(type) %>); From ae4d7f0531b97a57e1a681ec4f69f0c61dedd690 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 13 Jul 2020 16:18:28 -0400 Subject: [PATCH 2/2] test: update generated tests to not use async helper function --- .../angular_cli/src/app/app.component.spec.ts | 8 +++---- .../build_angular/src/karma/works_spec.ts | 24 +++++++++---------- .../src/app/app.component.spec.ts | 20 ++++++++-------- .../lib/src/lib/lib.component.spec.ts | 8 +++---- .../angular-app/src/app/app.component.spec.ts | 20 ++++++++-------- .../1.0-project/src/app/app.component.spec.ts | 20 ++++++++-------- .../1.7-project/src/app/app.component.spec.ts | 20 ++++++++-------- .../7.0-project/src/app/app.component.spec.ts | 8 +++---- .../lazy-comp/lazy-comp.component.spec.ts | 8 +++---- .../legacy-cli/e2e/tests/test/test-scripts.ts | 24 +++++++++---------- 10 files changed, 80 insertions(+), 80 deletions(-) diff --git a/integration/angular_cli/src/app/app.component.spec.ts b/integration/angular_cli/src/app/app.component.spec.ts index defeae1d79d6..e0dea2ba3678 100644 --- a/integration/angular_cli/src/app/app.component.spec.ts +++ b/integration/angular_cli/src/app/app.component.spec.ts @@ -1,14 +1,14 @@ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ AppComponent ], }).compileComponents(); - })); + }); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); diff --git a/packages/angular_devkit/build_angular/src/karma/works_spec.ts b/packages/angular_devkit/build_angular/src/karma/works_spec.ts index 3f8ca86c5ee9..287777f7423f 100644 --- a/packages/angular_devkit/build_angular/src/karma/works_spec.ts +++ b/packages/angular_devkit/build_angular/src/karma/works_spec.ts @@ -64,24 +64,24 @@ describe('Karma Builder', () => { } `, 'src/app/app.component.spec.ts': ` - import { TestBed, async } from '@angular/core/testing'; + import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ imports: [ ], declarations: [ AppComponent ] }).compileComponents(); - })); + }); - it('should not contain text that is hidden via css', async(() => { + it('should not contain text that is hidden via css', () => { const fixture = TestBed.createComponent(AppComponent); expect(fixture.nativeElement.innerText).not.toContain('Hello World'); - })); + }); });`, }); @@ -143,13 +143,13 @@ describe('Karma Builder', () => { } }`, 'src/app/app.component.spec.ts': ` - import { TestBed, async } from '@angular/core/testing'; + import { TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ imports: [ HttpClientModule ], @@ -157,13 +157,13 @@ describe('Karma Builder', () => { AppComponent ] }).compileComponents(); - })); + }); - it('should create the app', async(() => { + it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); - })); + }); });`, }); diff --git a/packages/angular_devkit/build_angular/test/hello-world-app/src/app/app.component.spec.ts b/packages/angular_devkit/build_angular/test/hello-world-app/src/app/app.component.spec.ts index b7a7162e8e1f..d3dde56aacc1 100644 --- a/packages/angular_devkit/build_angular/test/hello-world-app/src/app/app.component.spec.ts +++ b/packages/angular_devkit/build_angular/test/hello-world-app/src/app/app.component.spec.ts @@ -5,28 +5,28 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [AppComponent], }).compileComponents(); - })); - it('should create the app', async(() => { + }); + it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); - })); - it(`should have as title 'app'`, async(() => { + }); + it(`should have as title 'app'`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('app'); - })); - it('should render title in a h1 tag', async(() => { + }); + it('should render title in a h1 tag', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); - })); + }); }); diff --git a/packages/angular_devkit/build_ng_packagr/test/ng-packaged/projects/lib/src/lib/lib.component.spec.ts b/packages/angular_devkit/build_ng_packagr/test/ng-packaged/projects/lib/src/lib/lib.component.spec.ts index 6ef4e5debc9f..2694b8dea5a2 100644 --- a/packages/angular_devkit/build_ng_packagr/test/ng-packaged/projects/lib/src/lib/lib.component.spec.ts +++ b/packages/angular_devkit/build_ng_packagr/test/ng-packaged/projects/lib/src/lib/lib.component.spec.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LibComponent } from './lib.component'; @@ -13,12 +13,12 @@ describe('LibComponent', () => { let component: LibComponent; let fixture: ComponentFixture; - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ LibComponent ] }) .compileComponents(); - })); + }); beforeEach(() => { fixture = TestBed.createComponent(LibComponent); diff --git a/packages/angular_devkit/build_webpack/test/angular-app/src/app/app.component.spec.ts b/packages/angular_devkit/build_webpack/test/angular-app/src/app/app.component.spec.ts index 209e3256a9b3..869493ff9aeb 100644 --- a/packages/angular_devkit/build_webpack/test/angular-app/src/app/app.component.spec.ts +++ b/packages/angular_devkit/build_webpack/test/angular-app/src/app/app.component.spec.ts @@ -5,30 +5,30 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ AppComponent ], }).compileComponents(); - })); - it('should create the app', async(() => { + }); + it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); - })); - it(`should have as title 'app'`, async(() => { + }); + it(`should have as title 'app'`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('app'); - })); - it('should render title in a h1 tag', async(() => { + }); + it('should render title in a h1 tag', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); - })); + }); }); diff --git a/tests/legacy-cli/e2e/assets/1.0-project/src/app/app.component.spec.ts b/tests/legacy-cli/e2e/assets/1.0-project/src/app/app.component.spec.ts index c740bcd745ed..d715a39aa7e6 100644 --- a/tests/legacy-cli/e2e/assets/1.0-project/src/app/app.component.spec.ts +++ b/tests/legacy-cli/e2e/assets/1.0-project/src/app/app.component.spec.ts @@ -1,32 +1,32 @@ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ AppComponent ], }).compileComponents(); - })); + }); - it('should create the app', async(() => { + it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); - })); + }); - it(`should have as title 'app works!'`, async(() => { + it(`should have as title 'app works!'`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('app works!'); - })); + }); - it('should render title in a h1 tag', async(() => { + it('should render title in a h1 tag', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('app works!'); - })); + }); }); diff --git a/tests/legacy-cli/e2e/assets/1.7-project/src/app/app.component.spec.ts b/tests/legacy-cli/e2e/assets/1.7-project/src/app/app.component.spec.ts index bcbdf36b3e50..b7e5ffcd9bc1 100644 --- a/tests/legacy-cli/e2e/assets/1.7-project/src/app/app.component.spec.ts +++ b/tests/legacy-cli/e2e/assets/1.7-project/src/app/app.component.spec.ts @@ -1,27 +1,27 @@ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ AppComponent ], }).compileComponents(); - })); - it('should create the app', async(() => { + }); + it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); - })); - it(`should have as title 'app'`, async(() => { + }); + it(`should have as title 'app'`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('app'); - })); - it('should render title in a h1 tag', async(() => { + }); + it('should render title in a h1 tag', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!'); - })); + }); }); diff --git a/tests/legacy-cli/e2e/assets/7.0-project/src/app/app.component.spec.ts b/tests/legacy-cli/e2e/assets/7.0-project/src/app/app.component.spec.ts index 14df92cc2d95..15b4d442f5be 100644 --- a/tests/legacy-cli/e2e/assets/7.0-project/src/app/app.component.spec.ts +++ b/tests/legacy-cli/e2e/assets/7.0-project/src/app/app.component.spec.ts @@ -1,10 +1,10 @@ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { RouterModule } from '@angular/router'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ AppComponent ], @@ -12,7 +12,7 @@ describe('AppComponent', () => { RouterModule.forRoot([]) ], }).compileComponents(); - })); + }); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); diff --git a/tests/legacy-cli/e2e/assets/7.0-project/src/app/lazy/lazy-comp/lazy-comp.component.spec.ts b/tests/legacy-cli/e2e/assets/7.0-project/src/app/lazy/lazy-comp/lazy-comp.component.spec.ts index b8f42f6a5deb..9981b700abf6 100644 --- a/tests/legacy-cli/e2e/assets/7.0-project/src/app/lazy/lazy-comp/lazy-comp.component.spec.ts +++ b/tests/legacy-cli/e2e/assets/7.0-project/src/app/lazy/lazy-comp/lazy-comp.component.spec.ts @@ -1,4 +1,4 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LazyCompComponent } from './lazy-comp.component'; @@ -6,12 +6,12 @@ describe('LazyCompComponent', () => { let component: LazyCompComponent; let fixture: ComponentFixture; - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ LazyCompComponent ] }) .compileComponents(); - })); + }); beforeEach(() => { fixture = TestBed.createComponent(LazyCompComponent); diff --git a/tests/legacy-cli/e2e/tests/test/test-scripts.ts b/tests/legacy-cli/e2e/tests/test/test-scripts.ts index bf5299647efd..4114447796ae 100644 --- a/tests/legacy-cli/e2e/tests/test/test-scripts.ts +++ b/tests/legacy-cli/e2e/tests/test/test-scripts.ts @@ -28,35 +28,35 @@ export default function () { } `, 'src/app/app.component.spec.ts': stripIndent` - import { TestBed, async } from '@angular/core/testing'; + import { TestBed } from '@angular/core/testing'; import { AppComponent } from './app.component'; describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ + beforeEach(async () => { + await TestBed.configureTestingModule({ declarations: [ AppComponent ] }).compileComponents(); - })); + }); - it('should have access to string-script.js', async(() => { + it('should have access to string-script.js', () => { let app = TestBed.createComponent(AppComponent).debugElement.componentInstance; expect(app.stringScriptGlobalProp).toEqual('string-scripts.js'); - })); + }); - it('should have access to input-script.js', async(() => { + it('should have access to input-script.js', () => { let app = TestBed.createComponent(AppComponent).debugElement.componentInstance; expect(app.inputScriptGlobalProp).toEqual('input-scripts.js'); - })); + }); }); describe('Spec', () => { - it('should have access to string-script.js', async(() => { + it('should have access to string-script.js', () => { expect(stringScriptGlobal).toBe('string-scripts.js'); - })); + }); - it('should have access to input-script.js', async(() => { + it('should have access to input-script.js', () => { expect(inputScriptGlobal).toBe('input-scripts.js'); - })); + }); }); ` }))