javascript - No se puede retornar en el hook 'before' en cucumber-js
Actualmente estoy tratando de saltarme una prueba en cucumber-js basada en las etiquetas proporcionadas. Al revisar su documentación, parece bastante sencillo, lo siguiente debería funcionar.
Before({ tags: '@skip' }, async function() {
return 'skip'
})
Pero cuando hago esto, estoy obteniendo el siguiente error:
TSError: ⨯ Unable to compile TypeScript:
e2e/hooks/hooks.ts(36,1): error TS2769: No overload matches this call.
Overload 1 of 3, '(tags: string, code: TestCaseHookFunction): void', gave the following error.
Argument of type '{ tags: string; }' is not assignable to parameter of type 'string'.
Overload 2 of 3, '(options: IDefineTestCaseHookOptions, code: TestCaseHookFunction): void', gave the following error.
Argument of type '() => Promise<string>' is not assignable to parameter of type 'TestCaseHookFunction'.
Type '() => Promise<string>' is not assignable to type 'TestCaseHookFunctionWithoutParameter'.
Type 'Promise<string>' is not assignable to type 'void | Promise<void>'.
Type 'Promise<string>' is not assignable to type 'Promise<void>'.
Type 'string' is not assignable to type 'void'.
Nota: estoy usando TypeScript
Parece que no hay un método sobrecargado que te permita devolver una cadena. Profundicé en su código fuente y parece que no hay un método sobrecargado
export declare const Before: ((code: import("./support_code_library_builder/types").TestCaseHookFunction) => void) & ((tags: string, code: import("./support_code_library_builder/types").TestCaseHookFunction) => void) & ((options: import("./support_code_library_builder/types").IDefineTestCaseHookOptions, code: import("./support_code_library_builder/types").TestCaseHookFunction) => void);
¿Me estoy perdiendo de algo aquí? Soy bastante nuevo en TypeScript, así que es muy posible. Pero parece que cada método definido para la función before devuelve void.
Respuesta #1
Aquí está mi solución y tienes razón, es muy extraño.
usar el decorador // @ts-ignore.
import {
IDefineTestCaseHookOptions, TestCaseHookFunction
} from '@cucumber/cucumber/lib/support_code_library_builder/types';
// @ts-ignore
Before(function (testCase: IDefineTestCaseHookOptions, callback: TestCaseHookFunction): void {
console.log(testCase);
// @ts-ignore
callback();
});
```
