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]: Type for describe.each when importing from @jest/globals does not support const arrays #12294

Closed
dbartholomae opened this issue Feb 2, 2022 · 3 comments · Fixed by #12297

Comments

@dbartholomae
Copy link

Version

27.4.7

Steps to reproduce

  • Clone https://github.com/dbartholomae/jest-global-import-example
  • Run npm test

Expected behavior

No error

Actual behavior

describe.each([['foo'], ['bar']] as const) throws an error.

    failing-example.test.ts:8:15 - error TS2345: Argument of type 'readonly [readonly ["foo"], readonly ["bar"]]' is not assignable to parameter of type 'EachTable'.
      Property 'raw' is missing in type 'readonly [readonly ["foo"], readonly ["bar"]]' but required in type 'TemplateStringsArray'.

    8 describe.each([['foo'], ['bar']] as const)("The property %s", (prop) => {

Additional context

When importing types from @types/jest, the error does not occur, as can be seen from working-example.test.ts. It seems like the type definition in @jest/globals only defines types for a table with a template string, not for an array.

Leaving out const in the each call solves the type problem, but is not a solution overall, as it leads to a different type error later on.

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Binaries:
    Node: 14.16.0 - C:\Users\DANIEL~1\AppData\Local\Temp\fnm_multishells\24620_1643819406172\node.EXE
    npm: 6.14.11 - C:\Users\DANIEL~1\AppData\Local\Temp\fnm_multishells\24620_1643819406172\npm.CMD
  npmPackages:
    jest: ^27.4.7 => 27.4.7
@SimenB
Copy link
Member

SimenB commented Feb 3, 2022

@dbartholomae
Copy link
Author

Seems like someone else was faster :D

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

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 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants