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:

committed by
Igor Minar

parent
36a7705a44
commit
39abe7b7c1
@ -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';
|
||||
|
||||
|
@ -35,18 +35,14 @@
|
||||
* @param blockFn function to wrap. The function can return promise or be `async`.
|
||||
* @experimental
|
||||
*/
|
||||
export function withBody<T>(html: string, blockFn: T): T {
|
||||
return function(done: {(): void, fail(): void}) {
|
||||
export function withBody<T extends Function>(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);
|
||||
if (typeof afterEach == 'function') beforeEach(cleanupDocument);
|
||||
|
@ -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); };
|
||||
(<any>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(() => {
|
||||
|
Reference in New Issue
Block a user