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

[Bug]: Types no longer allow passing a named function to describe #12483

Closed
JoshuaKGoldberg opened this issue Feb 23, 2022 · 6 comments · Fixed by #12484
Closed

[Bug]: Types no longer allow passing a named function to describe #12483

JoshuaKGoldberg opened this issue Feb 23, 2022 · 6 comments · Fixed by #12484

Comments

@JoshuaKGoldberg
Copy link
Contributor

Version

27.0.6 and 28.0.0-alpha.4

Steps to reproduce

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgEwKYGcDGVgCNVwC+cAZlBCHAOQACAVhjAPQDmANhLgIZvpUDcAKEEkArgDtMMYBHFwQATwBiEqTLkAKAJSJCQwWiw58GxSsnTZAGjja4AXgB8urfyA

Expected behavior

No type errors on describe(myFunction, () => {})

Actual behavior

Argument of type '() => void' is not assignable to parameter of type 'string'.

Additional context

Allowing taking in class/function names in describe was added in #5154 and typed in @types/jest in DefinitelyTyped/DefinitelyTyped#23102.

Tests still pass while taking in a name; it's just the typings that are incorrect.

Environment

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    Yarn: 3.2.0 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/bin/npm
  npmPackages:
    jest: workspace:* => 28.0.0-alpha.4
@SimenB
Copy link
Member

SimenB commented Feb 23, 2022

Ah, good catch!

/cc @mrazauskas

@mrazauskas
Copy link
Contributor

Hm.. I was going through the discussion in the PR which added this feature. The maintainers seemed to be skeptical and the only convincing argument was legacy browsers #5154 (comment). Is this still an issue? IE is gone.

I have a feeling it might be equally good idea to deprecate this feature. Time comes and older Node version is not supported, the same about browsers.

https://github.com/facebook/jest/blob/c65bb4521597fb1ad65dacd778a26e04684b2872/packages/jest-util/src/convertDescriptorToString.ts#L11-L13

Instead one can easily have '123' (number), '' (undefined), 'true' (boolean, if you wish), someFunction.name (works too). So is this feature still relevant or is that just legacy code?

@SimenB
Copy link
Member

SimenB commented Feb 24, 2022

I don't really see a reason to remove the feature - it's a nice shorthand, and runtime support is already present, it's only the types that don't recognize it

@JoshuaKGoldberg
Copy link
Contributor Author

FWIW I agree with SimenB and think being able to to describe(myFunction) instead of describe(myFunction.name) is itself a nice feature. Keeping hardcoded strings like describe("myFunction") between refactorings is a pain.

@SimenB
Copy link
Member

SimenB commented Feb 24, 2022

https://github.com/facebook/jest/releases/tag/v28.0.0-alpha.5

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants