RNTL v14: Update Dependencies
This codemod updates your package.json file to prepare for React Native Testing Library v14 migration by:
- ✅ Removing @types/react-test-renderer (no longer needed)
- ✅ Removing react-test-renderer (replaced by universal-test-renderer)
- ✅ Moving @testing-library/react-native from dependencies to devDependencies if present
- ✅ Adding @testing-library/react-native@^14.0.0-alpha.5 to devDependencies if not present
- ✅ Updating @testing-library/react-native to ^14.0.0-alpha.5
- ✅ Adding universal-test-renderer@0.10.1 to devDependencies (always added)
What it does
This codemod automatically updates your package.json dependencies to match the requirements for RNTL v14. It:
-
Removes deprecated packages: @types/react-test-renderer and react-test-renderer are removed from all dependency types (dependencies, devDependencies, peerDependencies, optionalDependencies)
-
Moves RNTL to devDependencies: If @testing-library/react-native is in dependencies, it's moved to devDependencies
-
Ensures RNTL is present: If @testing-library/react-native is not present, it's added to devDependencies with version ^14.0.0-alpha.5
-
Updates RNTL version: Updates @testing-library/react-native to ^14.0.0-alpha.5
-
Adds universal-test-renderer: Always adds universal-test-renderer@0.10.1 to devDependencies
Usage
Running the codemod
bash
Example transformations
Before:
json
After:
json
Moving from dependencies to devDependencies:
Before:
json
After:
json
Adding if not present:
Before:
json
After:
json
Important Notes
-
After running the codemod, you'll need to run your package manager to install the new dependencies:
bash -
Version resolution: The codemod sets @testing-library/react-native to ^14.0.0-alpha.5. You can manually update this to a different version if needed.
-
Always adds packages: The codemod always ensures both @testing-library/react-native and universal-test-renderer are present in devDependencies, even if they weren't there before.
Testing
Run the test suite:
bash
Limitations
-
Package manager: The codemod updates package.json but doesn't run the package manager install command. You need to run npm install / yarn install / pnpm install manually after the codemod completes.
-
Version pinning: If you have a specific alpha version pinned, the codemod will update it to ^14.0.0-alpha.5. You may want to review and adjust the version after running the codemod.
-
Workspace projects: For monorepos with multiple package.json files, the codemod will process each one individually.
Migration Guide
- Run this codemod to update your dependencies
- Run your package manager to install the new dependencies:
bash
- Run the render-async codemod to update your test code:
bash
- Review and test your changes
- Update your RNTL version to a specific alpha version if needed
Contributing
If you find issues or have suggestions for improvements, please open an issue or submit a pull request to the React Native Testing Library repository.