test: fix typings for `DoneFn` (#25163)

This also fixes CI tests, which were accidentally broken in #24663.

PR Close #25163
This commit is contained in:
George Kalpakas 2018-07-27 19:14:12 +03:00 committed by Igor Minar
parent e8d4211d5c
commit 342678486d
9 changed files with 25 additions and 28 deletions

View File

@ -29,7 +29,7 @@ describe('largeform benchmark perf', () => {
[CreateAndDestroyWorker].forEach((worker) => { [CreateAndDestroyWorker].forEach((worker) => {
describe(worker.id, () => { describe(worker.id, () => {
it('should run for ng2', (done: any) => { it('should run for ng2', done => {
runLargeFormBenchmark({ runLargeFormBenchmark({
id: `largeform.ng2.${worker.id}`, id: `largeform.ng2.${worker.id}`,
url: 'all/benchmarks/src/largeform/ng2/index.html', url: 'all/benchmarks/src/largeform/ng2/index.html',

View File

@ -40,7 +40,7 @@ describe('largetable benchmark perf', () => {
[CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => { [CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => {
describe(worker.id, () => { describe(worker.id, () => {
it('should run for ng2', (done: any) => { it('should run for ng2', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.ng2.${worker.id}`, id: `largeTable.ng2.${worker.id}`,
url: 'all/benchmarks/src/largetable/ng2/index.html', url: 'all/benchmarks/src/largetable/ng2/index.html',
@ -48,7 +48,7 @@ describe('largetable benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should run for ng2 with ngSwitch', (done: any) => { it('should run for ng2 with ngSwitch', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.ng2_switch.${worker.id}`, id: `largeTable.ng2_switch.${worker.id}`,
url: 'all/benchmarks/src/largetable/ng2_switch/index.html', url: 'all/benchmarks/src/largetable/ng2_switch/index.html',
@ -56,7 +56,7 @@ describe('largetable benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should run for render3', (done: any) => { it('should run for render3', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.render3.${worker.id}`, id: `largeTable.render3.${worker.id}`,
url: 'all/benchmarks/src/largetable/render3/index.html', url: 'all/benchmarks/src/largetable/render3/index.html',
@ -65,7 +65,7 @@ describe('largetable benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should run for iv', (done: any) => { it('should run for iv', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.iv.${worker.id}`, id: `largeTable.iv.${worker.id}`,
url: 'all/benchmarks/src/largetable/iv/index.html', url: 'all/benchmarks/src/largetable/iv/index.html',
@ -74,7 +74,7 @@ describe('largetable benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should run for the baseline', (done: any) => { it('should run for the baseline', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.baseline.${worker.id}`, id: `largeTable.baseline.${worker.id}`,
url: 'all/benchmarks/src/largetable/baseline/index.html', url: 'all/benchmarks/src/largetable/baseline/index.html',
@ -83,7 +83,7 @@ describe('largetable benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should run for incremental-dom', (done: any) => { it('should run for incremental-dom', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.incremental_dom.${worker.id}`, id: `largeTable.incremental_dom.${worker.id}`,
url: 'all/benchmarks/src/largetable/incremental_dom/index.html', url: 'all/benchmarks/src/largetable/incremental_dom/index.html',

View File

@ -24,7 +24,7 @@ describe('tree benchmark perf', () => {
Benchmarks.forEach(benchmark => { Benchmarks.forEach(benchmark => {
describe(benchmark.id, () => { describe(benchmark.id, () => {
// This is actually a destroyOnly benchmark // This is actually a destroyOnly benchmark
it('should work for createOnly', (done: any) => { it('should work for createOnly', done => {
runTreeBenchmark({ runTreeBenchmark({
id: 'createOnly', id: 'createOnly',
benchmark, benchmark,
@ -33,7 +33,7 @@ describe('tree benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should work for createOnlyForReal', (done: any) => { it('should work for createOnlyForReal', done => {
runTreeBenchmark({ runTreeBenchmark({
id: 'createOnlyForReal', id: 'createOnlyForReal',
benchmark, benchmark,
@ -42,7 +42,7 @@ describe('tree benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should work for createDestroy', (done: any) => { it('should work for createDestroy', done => {
runTreeBenchmark({ runTreeBenchmark({
id: 'createDestroy', id: 'createDestroy',
benchmark, benchmark,
@ -53,13 +53,13 @@ describe('tree benchmark perf', () => {
}).then(done, done.fail); }).then(done, done.fail);
}); });
it('should work for update', (done: any) => { it('should work for update', done => {
runTreeBenchmark({id: 'update', benchmark, work: () => $(CreateBtn).click()}) runTreeBenchmark({id: 'update', benchmark, work: () => $(CreateBtn).click()})
.then(done, done.fail); .then(done, done.fail);
}); });
if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) { if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) {
it('should work for detectChanges', (done: any) => { it('should work for detectChanges', done => {
runTreeBenchmark({ runTreeBenchmark({
id: 'detectChanges', id: 'detectChanges',
benchmark, benchmark,

View File

@ -41,7 +41,7 @@ describe('largetable benchmark perf', () => {
[CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => { [CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => {
describe(worker.id, () => { describe(worker.id, () => {
it('should run for render3', (done) => { it('should run for render3', done => {
runTableBenchmark({ runTableBenchmark({
id: `largeTable.render3.${worker.id}`, id: `largeTable.render3.${worker.id}`,
url: 'index.html', url: 'index.html',

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {withBody} from '@angular/core/testing';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';

View File

@ -35,18 +35,14 @@
* @param blockFn function to wrap. The function can return promise or be `async`. * @param blockFn function to wrap. The function can return promise or be `async`.
* @experimental * @experimental
*/ */
export function withBody<T>(html: string, blockFn: T): T { export function withBody<T extends Function>(html: string, blockFn: T): T {
return function(done: {(): void, fail(): void}) { return function(done: DoneFn) {
ensureDocument(); ensureDocument();
let returnValue: any = undefined;
if (typeof blockFn === 'function') { if (typeof blockFn === 'function') {
document.body.innerHTML = html; document.body.innerHTML = html;
// TODO(i): I'm not sure why a cast is required here but otherwise I get const blockReturn = blockFn();
// TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'never' has
// no compatible call signatures.
let blockReturn = (blockFn as any)();
if (blockReturn instanceof Promise) { if (blockReturn instanceof Promise) {
blockReturn = blockReturn.then(done, done.fail); blockReturn.then(done, done.fail);
} else { } else {
done(); done();
} }
@ -124,4 +120,4 @@ export function cleanupDocument(): void {
} }
if (typeof beforeEach == 'function') beforeEach(ensureDocument); if (typeof beforeEach == 'function') beforeEach(ensureDocument);
if (typeof afterEach == 'function') beforeEach(cleanupDocument); if (typeof afterEach == 'function') beforeEach(cleanupDocument);

View File

@ -104,9 +104,9 @@ class BadTemplateUrl {
reject = rej; reject = rej;
}); });
originalJasmineIt = jasmine.getEnv().it; originalJasmineIt = jasmine.getEnv().it;
jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */): any => { jasmine.getEnv().it = (description: string, fn: (done: DoneFn) => void): any => {
const done = () => { resolve(null); }; const done = (() => resolve(null)) as DoneFn;
(<any>done).fail = (err: any /** TODO #9100 */) => { reject(err); }; done.fail = reject;
fn(done); fn(done);
return null; return null;
}; };
@ -115,7 +115,7 @@ class BadTemplateUrl {
const restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; }; 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(); const itPromise = patchJasmineIt();
it('should fail with an error from a promise', async(() => { it('should fail with an error from a promise', async(() => {

View File

@ -148,7 +148,7 @@ export declare type TestModuleMetadata = {
export declare function tick(millis?: number): void; export declare function tick(millis?: number): void;
/** @experimental */ /** @experimental */
export declare function withBody<T>(html: string, blockFn: T): T; export declare function withBody<T extends Function>(html: string, blockFn: T): T;
/** @experimental */ /** @experimental */
export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper; export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
/// <reference types="jasminewd2" />
/** /**
* Extended typings for `jasminewd2`. * Extended typings for `jasminewd2`.
* *