jest icon indicating copy to clipboard operation
jest copied to clipboard

Error when using async functions: "ReferenceError: async is not defined"

Open david-arteaga opened this issue 5 years ago • 1 comments

🐛 Bug Report

Jest throws an ReferenceError: async is not defined error when the async keyword is used and there is a comment in the function args list.

To Reproduce

Define the following function in any file tested by Jest:

const foo = async (/** any text  */ name) => name;

and run Jest.

I came across this bug using Typescript JSDoc annotations in JS files (ex: /** @type {string} */). This is just the use case I have for being able to put /** ... */ style comments inline in async functions.

But still, it is valid Javascript and there is no reason Jest should throw an error when it encounters it.

Expected behavior

The test should execute correctly and not

Link to repl or repo (highly encouraged)

https://repl.it/@david_arteaga/jest-async-bug

envinfo

System:
  OS: macOS 10.15.7
  CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
Binaries:
  Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node
  Yarn: 1.22.4 - ~/.yarn/bin/yarn
  npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm
npmPackages:
  jest: ^26.6.3 => 26.6.3

david-arteaga avatar Nov 18 '20 15:11 david-arteaga

I'm still having this error 2 years later.

pgmorgan avatar Aug 02 '22 13:08 pgmorgan

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Aug 02 '23 14:08 github-actions[bot]

Can not reproduce this. Tried Jest 26 and higher versions.

mrazauskas avatar Aug 03 '23 10:08 mrazauskas

As noted in the Bug Report template, all bug reports requires a minimal reproduction. Please open up a new issue providing one. Read more at https://stackoverflow.com/help/minimal-reproducible-example.

github-actions[bot] avatar Aug 03 '23 10:08 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Sep 03 '23 00:09 github-actions[bot]