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

[@jest/globals] only exporting type #9922

Closed
BenGladman opened this issue Apr 29, 2020 · 6 comments · Fixed by #9925
Closed

[@jest/globals] only exporting type #9922

BenGladman opened this issue Apr 29, 2020 · 6 comments · Fixed by #9925

Comments

@BenGladman
Copy link

BenGladman commented Apr 29, 2020

🐛 Bug Report

The new @jest/globals package only exports the types of the functions, and typescript shows an error when I try to use them

To Reproduce

Steps to reproduce the behavior:

  • new repo
  • npm install jest
  • my.test.ts:
import { describe, expect, test } from '@jest/globals';

describe("d", () => {
  test("t", () => {
    expect(true).toBe(true);
  });
});
  • result:
    image

Expected behavior

no typescript errors

Link to repl or repo (highly encouraged)

https://github.com/BenGladman/jest-issue

envinfo

  System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 12.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.19.1 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.2 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^25.5.1 => 25.5.1
@BenGladman BenGladman changed the title [@jest/globals] only importing type [@jest/globals] only exporting type Apr 29, 2020
@tmkn
Copy link

tmkn commented Apr 29, 2020

Seems like 25.5.0 severely broke TypeScript support. When I update from 25.4.0 to 25.5.0, describe, test & expect cannot be found, even though I have @types/jest installed:

ERROR in /home/vsts/work/1/s/src/App.test.tsx
[tsl] ERROR in /home/vsts/work/1/s/src/App.test.tsx(7,1)
      TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.

ERROR in /home/vsts/work/1/s/src/App.test.tsx
[tsl] ERROR in /home/vsts/work/1/s/src/App.test.tsx(8,5)
      TS2593: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.

ERROR in /home/vsts/work/1/s/src/App.test.tsx
[tsl] ERROR in /home/vsts/work/1/s/src/App.test.tsx(11,9)
      TS2304: Cannot find name 'expect'.

so I tried the @jest/globals package but it complains with the error mentioned in this ticket.

In any case I would like to not do any changes to my code since it's only a minor version upgrade, as said everything works just fine with 25.4.0

@SimenB
Copy link
Member

SimenB commented Apr 29, 2020

Aww, that's too bad. I'll fix that. (somehow... export dummy functions?).

@tmkn Your first issue is different. 25.5 works fine for me using TS at work.

EDIT: Hmm, it works for me importing from @jest/globals...

@tmkn
Copy link

tmkn commented Apr 29, 2020

@SimenB yes I know, I wasn't sure if I should create a ticket or if I'm missing something obvious since I didn't see a ticket yet and dependabot also sees a 98% success rate.

Just to be clear, updating to 25.5.0 still leaves describe, test, expect globally available? Since it's not a major version upgrade? If it worked for 25.4.0 then everything should work as is for 25.5.0?

@SimenB
Copy link
Member

SimenB commented Apr 29, 2020

They are all still globally available, yes.

@SimenB
Copy link
Member

SimenB commented Apr 29, 2020

@BenGladman fix published in 25.5.2 🙂

@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