在 V6 中,为了跳过场景,我使用了 Before each scenario 钩子
Before({ tags: '<strong i="6">@ignore</strong>' }, async function () {
return 'skipped';
});
同样的代码在 v7 中不再使用 typescript 编译:
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 '(this: CustomWorld) => Promise<string>' is not assignable to parameter of type 'TestCaseHookFunction'.
Type '(this: CustomWorld) => 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>'.
在 v7 中跳过场景的正确方法是什么?
谢谢
我刚刚在向Serenity/JS添加对 Cucumber v7 的支持时遇到了完全相同的问题。
在我看来,这是类型定义的问题,而不是实际功能的问题,它的工作方式与在 v6 中使用的方式完全相同。
@charlierudolph / @davidjgoss ,您介意检查一下我下面的想法是否正确吗?
在support_code_library_builder/types.ts
有以下定义:
export type TestCaseHookFunctionWithoutParameter = () => void | Promise<void>
export type TestCaseHookFunctionWithParameter = (
arg: ITestCaseHookParameter
) => void | Promise<void>
由于黄瓜允许钩返回void
,一个string
的'skipped'
或'pending'
或Promise
与这些结果中的一个,改进的实现可能看起来或多或少是这样的:
export type TestCaseHookFunctionResult = 'skipped' | 'pending' | void
export type TestCaseHookFunctionWithoutParameter = () => TestCaseHookFunctionResult | Promise<TestCaseHookFunctionResult>
export type TestCaseHookFunctionWithParameter = (
arg: ITestCaseHookParameter
) => TestCaseHookFunctionResult | Promise<TestCaseHookFunctionResult>
在引入此或类似更改之前,此问题的解决方法是指定测试挂钩,如下所示:
import { Before } from '@cucumber/cucumber';
Before({ tags: '<strong i="25">@ignore</strong>' }, function () {
return 'skipped' as any;
});
嗨@jan-molak,非常感谢您的反馈,您的解决方法非常有效!
感谢@jan-molak 的解决方法 - 我很快就会看看这个。
最有用的评论
我刚刚在向Serenity/JS添加对 Cucumber v7 的支持时遇到了完全相同的问题。
在我看来,这是类型定义的问题,而不是实际功能的问题,它的工作方式与在 v6 中使用的方式完全相同。
@charlierudolph / @davidjgoss ,您介意检查一下我下面的想法是否正确吗?
在
support_code_library_builder/types.ts
有以下定义:由于黄瓜允许钩返回
void
,一个string
的'skipped'
或'pending'
或Promise
与这些结果中的一个,改进的实现可能看起来或多或少是这样的:在引入此或类似更改之前,此问题的解决方法是指定测试挂钩,如下所示: