Navigation Menu

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

.each is unusable with @jest/globals #10447

Closed
danielmoore opened this issue Aug 25, 2020 · 3 comments 路 Fixed by #10488
Closed

.each is unusable with @jest/globals #10447

danielmoore opened this issue Aug 25, 2020 · 3 comments 路 Fixed by #10488

Comments

@danielmoore
Copy link

馃悰 Bug Report

The return type of test.each is void | ((title: string, test: EachTestFn<TestFn>, timeout?: number | undefined) => void).

It should not include void, as this makes the result uncallable.

To Reproduce

With Jest v26.4.2 and Typescript v4.0.2, create each.test.ts.

import { expect, test } from '@jest/globals';

const items = test.each([['foo'], ['bar']]);

items('Test %s', item => {
  expect(item).toHaveProperty('length', 3);
});

test.each`
item
foo
bar
`(item => {
  expect(item).toHaveProperty('length', 3);
});

Steps to reproduce the behavior:

tsc produces:

each.test.ts:5:1 - error TS2349: This expression is not callable.
  Not all constituents of type 'void | ((title: string, test: EachTestFn<TestFn>, timeout?: number | undefined) => void)' are callable.
    Type 'void' has no call signatures.

5 items('Test %s', item => {
  ~~~~~

each.test.ts:9:1 - error TS2349: This expression is not callable.
  Not all constituents of type 'void | ((title: string, test: EachTestFn<TestFn>, timeout?: number | undefined) => void)' are callable.
    Type 'void' has no call signatures.

  9 test.each`
    ~~~~~~~~~~
 10   item
    ~~~~~~
...
 12 bar
    ~~~
 13 `(item => {
    ~


Found 2 errors.

Expected behavior

The given tests should compile.

envinfo

  System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
  Binaries:
    Node: 14.8.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.7 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.4.2 => 26.4.2
@scttcper
Copy link
Contributor

scttcper commented Sep 1, 2020

Running into the same thing, seems to have been changed in #9326

@SimenB
Copy link
Member

SimenB commented Sep 7, 2020

Help with improving types is very much welcome 馃憤 Source is here: https://github.com/SimenB/jest/blob/c5785b9a71cc2edd8091cf67eae000c76010315c/packages/jest-types/src/Global.ts#L39-L48

We've recently landed the beginning of types tests to avoid these sorts of things, but it's not very comprehensive yet

@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 May 11, 2021
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