简体   繁体   English

在 cucumber-js 中的钩子之前无法返回

[英]Unable to return in before hook in cucumber-js

Currently I am trying to skip a test in cucumber-js based on tags provided.目前,我正在尝试根据提供的标签跳过 cucumber-js 中的测试。 Looking through their docs it seems pretty straight forward, the following should work.浏览他们的文档似乎很简单,以下应该有效。

Before({ tags: '@skip' }, async function() {
  return 'skip'
})

But when I do this I am getting the following 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'.

Note: I am using typescript注意:我使用的是 typescript

There seems to be no overloaded method that allows you to return a string.似乎没有允许您返回字符串的重载方法。 I dug into their source code it does seem to be that there is no overloaded method我挖掘了他们的源代码,似乎没有重载方法

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);

Am I missing something here?我在这里错过了什么吗? I am fairly new to typescript, so very possible.我对 typescript 相当陌生,所以很有可能。 But it seems as if every method defined for the before function returns void.但似乎为之前的 function 定义的每个方法都返回 void。

Here is my solution and you are right it's so weird.这是我的解决方案,你说得对,这太奇怪了。

use // @ts-ignore decorator.使用// @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();
});

```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM