jest
jest copied to clipboard
Error when using async functions: "ReferenceError: async is not defined"
🐛 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
I'm still having this error 2 years later.
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.
Can not reproduce this. Tried Jest 26 and higher versions.
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.
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.