From 9af3c9654ae8e2cb10d49770dd3438aec038fcef Mon Sep 17 00:00:00 2001 From: Xun Sun Date: Tue, 7 Feb 2023 06:16:07 -0800 Subject: [PATCH] switch from `@types/jest` to `@jest/globals` (#36068) Summary: Originally proposed in https://github.com/react-native-community/discussions-and-proposals/discussions/592 Main changes are: - Explicitly importing the global APIs in `App.test.tsx` - Drop `types/jest` from the devDependency list Benefits of these changes will be: - Keep in line with Jest's recommended practice - Remove a dev-dependency to make dependencies slimmer References: - https://github.com/facebook/jest/pull/13133 - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62037 ## Changelog [GENERAL] [CHANGED] - Switch from `types/jest` to `jest/globals` for new react-native projects Pull Request resolved: https://github.com/facebook/react-native/pull/36068 Test Plan: 1. Create a new RN project from the modified template 2. Ensure yarn test passes 3. Ensure IDEs do not complain about `App.test.tsx` Reviewed By: cipolleschi Differential Revision: D43080151 Pulled By: cortinico fbshipit-source-id: c9161cb930c78f3a1eaa08ccb6483aa38d52fa3c --- template/__tests__/App.test.tsx | 3 +++ template/package.json | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/template/__tests__/App.test.tsx b/template/__tests__/App.test.tsx index 178476699b6055..3413ac1c403683 100644 --- a/template/__tests__/App.test.tsx +++ b/template/__tests__/App.test.tsx @@ -6,6 +6,9 @@ import 'react-native'; import React from 'react'; import App from '../App'; +// Note: import explicitly to use the types shiped with jest. +import {it} from '@jest/globals'; + // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; diff --git a/template/package.json b/template/package.json index 3ac504d528f1e8..cf3b10d19e9e0e 100644 --- a/template/package.json +++ b/template/package.json @@ -19,7 +19,6 @@ "@babel/runtime": "^7.12.5", "@react-native/eslint-config": "^0.72.1", "@tsconfig/react-native": "^2.0.2", - "@types/jest": "^29.2.1", "@types/react": "^18.0.24", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.2.1",