Mmdjastrzebski

rntl-v14-async-functions

Codemod to migrate sync RNTL function and method calls to async for RNTL v14

transformationmigration
Public
46 executions
0 stars
How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

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

  1. Run the codemod on your test files
  2. Review the changes
  3. Manually update any remaining helper functions if needed
  4. Update your RNTL version to v14 (rntl-v14-update-deps codemod)
  5. Run your tests to verify everything works
Before

This is one example from the codemod's test cases. The codemod may handle many more cases.

Ready to contribute?

Build your own codemod and share it with the community.