fix(tapbundle): Fix TypeScript IDE warning about tapTools parameter possibly being undefined

This commit is contained in:
Juergen Kunz
2025-07-24 22:24:52 +00:00
parent e4fc6623ea
commit 008844a9e2
3 changed files with 14 additions and 5 deletions

View File

@@ -11,9 +11,9 @@ import { HrtMeasurement } from '@push.rocks/smarttime';
// interfaces
export type TTestStatus = 'success' | 'error' | 'pending' | 'errorAfterSuccess' | 'timeout' | 'skipped';
export interface ITestFunction<T> {
(tapTools?: TapTools): Promise<T>;
}
export type ITestFunction<T> =
| ((tapTools: TapTools) => Promise<T>)
| (() => Promise<T>);
export class TapTest<T = unknown> {
public description: string;
@@ -173,7 +173,9 @@ export class TapTest<T = unknown> {
}
// Run the test function with potential timeout
const testPromise = this.testFunction(this.tapTools);
const testPromise = this.testFunction.length === 0
? (this.testFunction as () => Promise<T>)()
: (this.testFunction as (tapTools: TapTools) => Promise<T>)(this.tapTools);
const testReturnValue = timeoutPromise
? await Promise.race([testPromise, timeoutPromise])
: await testPromise;