RNTL v14: Make render(), act(), renderHook(), and fireEvent() calls async
This codemod migrates your test files from React Native Testing Library v13 to v14 by automatically transforming synchronous function calls to async versions and making test functions async when needed.
What it does
- Transforms render(), act(), renderHook(), and fireEvent() calls to await render(), await act(), etc.
- Makes test functions (test(), it(), hooks) async when needed
- Handles fireEvent.press(), fireEvent.changeText(), fireEvent.scroll(), screen.rerender(), screen.unmount(), and renderer methods
- Only transforms calls imported from @testing-library/react-native
Usage
bash
Custom render functions
If you have custom render helper functions (like renderWithProviders, renderWithTheme), specify them so they get transformed too:
bash
Example
Before:
typescript
After:
typescript
Limitations
- Helper functions are not transformed by default (use customRenderFunctions param if needed)
- Namespace imports (import * as RNTL) are not handled
Next steps
- Run the codemod on your test files
- Review the changes
- Manually update any remaining helper functions if needed
- Update your RNTL version to v14 (rntl-v14-update-deps codemod)
- Run your tests to verify everything works