From 342678486dc08c82ab5a0dd89f93b67567e4e964 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 27 Jul 2018 19:14:12 +0300 Subject: [PATCH] test: fix typings for `DoneFn` (#25163) This also fixes CI tests, which were accidentally broken in #24663. PR Close #25163 --- modules/benchmarks/e2e_test/largeform_perf.ts | 2 +- modules/benchmarks/e2e_test/largetable_perf.ts | 12 ++++++------ modules/benchmarks/e2e_test/tree_perf.ts | 10 +++++----- .../src/largetable/largetable_perf.spec.ts | 2 +- .../bundling/hello_world_r2/treeshaking_spec.ts | 1 - packages/core/testing/src/render3.ts | 14 +++++--------- .../test/testing_public_browser_spec.ts | 8 ++++---- tools/public_api_guard/core/testing.d.ts | 2 +- tools/types-ext/jasminewd2.d.ts | 2 ++ 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/modules/benchmarks/e2e_test/largeform_perf.ts b/modules/benchmarks/e2e_test/largeform_perf.ts index 63aaebd3ed..42165a0358 100644 --- a/modules/benchmarks/e2e_test/largeform_perf.ts +++ b/modules/benchmarks/e2e_test/largeform_perf.ts @@ -29,7 +29,7 @@ describe('largeform benchmark perf', () => { [CreateAndDestroyWorker].forEach((worker) => { describe(worker.id, () => { - it('should run for ng2', (done: any) => { + it('should run for ng2', done => { runLargeFormBenchmark({ id: `largeform.ng2.${worker.id}`, url: 'all/benchmarks/src/largeform/ng2/index.html', diff --git a/modules/benchmarks/e2e_test/largetable_perf.ts b/modules/benchmarks/e2e_test/largetable_perf.ts index 045c5ef56a..2cfabb9634 100644 --- a/modules/benchmarks/e2e_test/largetable_perf.ts +++ b/modules/benchmarks/e2e_test/largetable_perf.ts @@ -40,7 +40,7 @@ describe('largetable benchmark perf', () => { [CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => { describe(worker.id, () => { - it('should run for ng2', (done: any) => { + it('should run for ng2', done => { runTableBenchmark({ id: `largeTable.ng2.${worker.id}`, url: 'all/benchmarks/src/largetable/ng2/index.html', @@ -48,7 +48,7 @@ describe('largetable benchmark perf', () => { }).then(done, done.fail); }); - it('should run for ng2 with ngSwitch', (done: any) => { + it('should run for ng2 with ngSwitch', done => { runTableBenchmark({ id: `largeTable.ng2_switch.${worker.id}`, url: 'all/benchmarks/src/largetable/ng2_switch/index.html', @@ -56,7 +56,7 @@ describe('largetable benchmark perf', () => { }).then(done, done.fail); }); - it('should run for render3', (done: any) => { + it('should run for render3', done => { runTableBenchmark({ id: `largeTable.render3.${worker.id}`, url: 'all/benchmarks/src/largetable/render3/index.html', @@ -65,7 +65,7 @@ describe('largetable benchmark perf', () => { }).then(done, done.fail); }); - it('should run for iv', (done: any) => { + it('should run for iv', done => { runTableBenchmark({ id: `largeTable.iv.${worker.id}`, url: 'all/benchmarks/src/largetable/iv/index.html', @@ -74,7 +74,7 @@ describe('largetable benchmark perf', () => { }).then(done, done.fail); }); - it('should run for the baseline', (done: any) => { + it('should run for the baseline', done => { runTableBenchmark({ id: `largeTable.baseline.${worker.id}`, url: 'all/benchmarks/src/largetable/baseline/index.html', @@ -83,7 +83,7 @@ describe('largetable benchmark perf', () => { }).then(done, done.fail); }); - it('should run for incremental-dom', (done: any) => { + it('should run for incremental-dom', done => { runTableBenchmark({ id: `largeTable.incremental_dom.${worker.id}`, url: 'all/benchmarks/src/largetable/incremental_dom/index.html', diff --git a/modules/benchmarks/e2e_test/tree_perf.ts b/modules/benchmarks/e2e_test/tree_perf.ts index ceddb69ed1..12034c7e07 100644 --- a/modules/benchmarks/e2e_test/tree_perf.ts +++ b/modules/benchmarks/e2e_test/tree_perf.ts @@ -24,7 +24,7 @@ describe('tree benchmark perf', () => { Benchmarks.forEach(benchmark => { describe(benchmark.id, () => { // This is actually a destroyOnly benchmark - it('should work for createOnly', (done: any) => { + it('should work for createOnly', done => { runTreeBenchmark({ id: 'createOnly', benchmark, @@ -33,7 +33,7 @@ describe('tree benchmark perf', () => { }).then(done, done.fail); }); - it('should work for createOnlyForReal', (done: any) => { + it('should work for createOnlyForReal', done => { runTreeBenchmark({ id: 'createOnlyForReal', benchmark, @@ -42,7 +42,7 @@ describe('tree benchmark perf', () => { }).then(done, done.fail); }); - it('should work for createDestroy', (done: any) => { + it('should work for createDestroy', done => { runTreeBenchmark({ id: 'createDestroy', benchmark, @@ -53,13 +53,13 @@ describe('tree benchmark perf', () => { }).then(done, done.fail); }); - it('should work for update', (done: any) => { + it('should work for update', done => { runTreeBenchmark({id: 'update', benchmark, work: () => $(CreateBtn).click()}) .then(done, done.fail); }); if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) { - it('should work for detectChanges', (done: any) => { + it('should work for detectChanges', done => { runTreeBenchmark({ id: 'detectChanges', benchmark, diff --git a/modules/benchmarks/src/largetable/largetable_perf.spec.ts b/modules/benchmarks/src/largetable/largetable_perf.spec.ts index 90d08cc24f..29408c1ffd 100644 --- a/modules/benchmarks/src/largetable/largetable_perf.spec.ts +++ b/modules/benchmarks/src/largetable/largetable_perf.spec.ts @@ -41,7 +41,7 @@ describe('largetable benchmark perf', () => { [CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => { describe(worker.id, () => { - it('should run for render3', (done) => { + it('should run for render3', done => { runTableBenchmark({ id: `largeTable.render3.${worker.id}`, url: 'index.html', diff --git a/packages/core/test/bundling/hello_world_r2/treeshaking_spec.ts b/packages/core/test/bundling/hello_world_r2/treeshaking_spec.ts index 66882ac549..45ea9d78ce 100644 --- a/packages/core/test/bundling/hello_world_r2/treeshaking_spec.ts +++ b/packages/core/test/bundling/hello_world_r2/treeshaking_spec.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import {withBody} from '@angular/core/testing'; import * as fs from 'fs'; import * as path from 'path'; diff --git a/packages/core/testing/src/render3.ts b/packages/core/testing/src/render3.ts index e7cdcd3a64..94f359be17 100644 --- a/packages/core/testing/src/render3.ts +++ b/packages/core/testing/src/render3.ts @@ -35,18 +35,14 @@ * @param blockFn function to wrap. The function can return promise or be `async`. * @experimental */ -export function withBody(html: string, blockFn: T): T { - return function(done: {(): void, fail(): void}) { +export function withBody(html: string, blockFn: T): T { + return function(done: DoneFn) { ensureDocument(); - let returnValue: any = undefined; if (typeof blockFn === 'function') { document.body.innerHTML = html; - // TODO(i): I'm not sure why a cast is required here but otherwise I get - // TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'never' has - // no compatible call signatures. - let blockReturn = (blockFn as any)(); + const blockReturn = blockFn(); if (blockReturn instanceof Promise) { - blockReturn = blockReturn.then(done, done.fail); + blockReturn.then(done, done.fail); } else { done(); } @@ -124,4 +120,4 @@ export function cleanupDocument(): void { } if (typeof beforeEach == 'function') beforeEach(ensureDocument); -if (typeof afterEach == 'function') beforeEach(cleanupDocument); \ No newline at end of file +if (typeof afterEach == 'function') beforeEach(cleanupDocument); diff --git a/packages/platform-browser-dynamic/test/testing_public_browser_spec.ts b/packages/platform-browser-dynamic/test/testing_public_browser_spec.ts index f219a92ffe..70d733e1bb 100644 --- a/packages/platform-browser-dynamic/test/testing_public_browser_spec.ts +++ b/packages/platform-browser-dynamic/test/testing_public_browser_spec.ts @@ -104,9 +104,9 @@ class BadTemplateUrl { reject = rej; }); originalJasmineIt = jasmine.getEnv().it; - jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */): any => { - const done = () => { resolve(null); }; - (done).fail = (err: any /** TODO #9100 */) => { reject(err); }; + jasmine.getEnv().it = (description: string, fn: (done: DoneFn) => void): any => { + const done = (() => resolve(null)) as DoneFn; + done.fail = reject; fn(done); return null; }; @@ -115,7 +115,7 @@ class BadTemplateUrl { const restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; }; - it('should fail when an ResourceLoader fails', (done: any /** TODO #9100 */) => { + it('should fail when an ResourceLoader fails', done => { const itPromise = patchJasmineIt(); it('should fail with an error from a promise', async(() => { diff --git a/tools/public_api_guard/core/testing.d.ts b/tools/public_api_guard/core/testing.d.ts index f7676a5f27..391d63920f 100644 --- a/tools/public_api_guard/core/testing.d.ts +++ b/tools/public_api_guard/core/testing.d.ts @@ -148,7 +148,7 @@ export declare type TestModuleMetadata = { export declare function tick(millis?: number): void; /** @experimental */ -export declare function withBody(html: string, blockFn: T): T; +export declare function withBody(html: string, blockFn: T): T; /** @experimental */ export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper; diff --git a/tools/types-ext/jasminewd2.d.ts b/tools/types-ext/jasminewd2.d.ts index b02a501695..3f87bc26ae 100644 --- a/tools/types-ext/jasminewd2.d.ts +++ b/tools/types-ext/jasminewd2.d.ts @@ -6,6 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ +/// + /** * Extended typings for `jasminewd2`. *