Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeforeStep and AfterStep hooks do not allow asynchronous functions - linting (es-lint) error #2037

Closed
ansonallard opened this issue May 10, 2022 · 3 comments · Fixed by #2038

Comments

@ansonallard
Copy link

👓 What did you see?

The cucumber-js api reference for BeforeStep and AfterStep indicates that one can use async functions as the function parameter to BeforeStep and AfterStep, just like Before/After and BeforeAll/AfterAll (API reference). However, when attempting to use an async function as an argument to AfterStep, I got the following typescript linting error:
Promise returned in function argument where a void return was expected

After doing some poking around, of the three hook types, the TestStepHookFunction type only allows for a return type of void, whereas the other two types, TestStepHookFunction and TestStepFunction have the following return types: any | Promise<any> (code).

✅ What did you expect to see?

I expected that TestStepHookFunction, TestStepHookFunction, and TestStepFunction all had the return type of any | Promise<any>.

📦 Which tool/library version are you using?

Cucumber-js version: 7.3.2
Typescript version: 4.6.3
eslint: 8.12.0

🔬 How could we reproduce it?

Steps to reproduce the behavior:

  1. Install cucumber-js version 7.3.2
  2. Install and apply eslint version 8.12.0
  3. Create a BeforeStep and pass in an async function, something like:
BeforeStep(async function(): Promise<void> {
await fetch("http://github.com");
})
  1. Linter/compiler throws expected error: Promise returned in function argument where a void return was expected

📚 Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

@aurelien-reeves
Copy link
Contributor

Hello @ansonallard :)

The api reference applies to latest version of cucumber-js: >=8.0

Could you please make a try with the latest version?

@ansonallard
Copy link
Author

Hey @aurelien-reeves,

I upgraded to cucumber js version 8.2.0 and was still experiencing the same issue.

Looks like @davidjgoss found the issue with the return types.

@davidjgoss
Copy link
Contributor

This fix has been released in 8.2.1 https://github.com/cucumber/cucumber-js/releases/tag/v8.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants