Skip to content

Commit

Permalink
switch from @types/jest to @jest/globals (#36068)
Browse files Browse the repository at this point in the history
Summary:
Originally proposed in react-native-community/discussions-and-proposals#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:
- jestjs/jest#13133
- DefinitelyTyped/DefinitelyTyped#62037

## Changelog

[GENERAL] [CHANGED] - Switch from `types/jest` to `jest/globals` for new react-native projects

Pull Request resolved: #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
  • Loading branch information
UNIDY2002 authored and facebook-github-bot committed Feb 7, 2023
1 parent 7adf6b1 commit 9af3c96
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 3 additions & 0 deletions template/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 0 additions & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9af3c96

Please sign in to comment.