jest-dom icon indicating copy to clipboard operation
jest-dom copied to clipboard

`@types/jest` dependency should be changed to `@jest/types`

Open kompot opened this issue 3 years ago • 6 comments

  • @testing-library/jest-dom version: 5.14.1
  • @types/testing-library__jest-dom version: 5.14
  • node version: 14
  • npm (or yarn) version: yarn 1.2

Problem description:

Looks like Jest v27 types are not supported by @types/jest and were moved to @jest/types.

Suggested solution:

Should @types/testing-library__jest-dom also consider upgrading this dependency?

As I can see @jest/types do support jest < 27. Seems like a safe upgrade.

kompot avatar Jul 05 '21 09:07 kompot

+1. Looks like @types/testing-library__jest-dom depends on [email protected] and if jest is upgraded to v27, the two different version of pretty-format is causing problem possibly because [email protected] exports a different value

chbdetta avatar Jul 26 '21 22:07 chbdetta

any progress on this? This is starting to turn into a problem for us

markusv avatar Dec 20 '21 08:12 markusv

@markusv I may be able to take care of this in a week or two. But maybe you could take a shot at it? You are welcome to make a pull request contributing this change, and I'll gladly review and release when it's all good.

gnapse avatar Dec 22 '21 12:12 gnapse

Having types in dependencies is actually conflicts with Vitest: https://github.com/testing-library/jest-dom/issues/427

sheremet-va avatar Jan 14 '22 13:01 sheremet-va

Issue has resurfaced with breaking changes introduced with Jest 28. @types/jest hasn't been updated yet, this causes a type error since @testing-library/jest-dom uses @types/jest v27:

	jest.useFakeTimers({
		legacyFakeTimers: true,
	});

kgregory avatar May 09 '22 13:05 kgregory

We've also recently encountered typing issues due to the conflict of Jest 28 vs. the @types/jest things that are referenced from @testing-library/jest-dom. Especially with the issue that the mocked helper previously in ts-jest/utils was moved to jest directly. Jest states to use import { jest } from '@jest/globals'; - however, this will then break jest.mock usage somehow (not sure why).

To work around this I'm using a jest.ts that get's included with the following namespace augmentation:

import type { jest as globalJest } from '@jest/globals';

declare global {
  namespace jest {
    const mocked: typeof globalJest.mocked;
  }
}

Maybe this helps someone...

rose-m avatar May 10 '22 09:05 rose-m

@jest/types is not a replacement for @types/jest. @jest/types exports some TypeScript types for internal Jest packages so external packages can import them, but it does not provide global types or config types. You would want to use it if you were writing a Jest package, not a Testing Library test.

I'm going to close this for now as I don't see a need for us to use @jest/types now, and removing @types/jest would be a potentially confusing breaking change. @types/jest is still actively maintained by the community and recommended by Jest. If you need help with it, please refer to the DefinitelyTyped discussions.

nickserv avatar Sep 19 '22 09:09 nickserv