callstack / react-native-testing-library

🦉 Simple and complete React Native testing utilities that encourage good testing practices.
https://callstack.github.io/react-native-testing-library/
MIT License
3.07k stars 271 forks source link

fix(user-event): Decouple press events from Jest dependency #1571

Closed JoseLion closed 6 months ago

JoseLion commented 6 months ago

Summary

Solves #1568 by decoupling press events in user-event from Jest dependency. As mentioned in the issue, this is done by replacing instances of jest.fn() with a simple noop() function, which does not cause any breaking change.

Additionally, it solves a small bug with warnAboutRealTimersIfNeeded() that caused the warning to be triggered even when RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS is present.

Test plan

This PR can be tested following the issue's Steps to Reproduce:

  1. Setup test without Jest. For example, using Mocha.js together with react-native-testing-mocks.
  2. Create a simple test containing a userEvent.press(..) call
  3. Because Jest is not present in the project, an error should be triggered: TypeError: event.persist is not a function
  4. Apply this PR changes and run the test again
  5. The error should be gone and the test runs as expected
codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 95.61%. Comparing base (a282d1e) to head (3df8445). Report is 6 commits behind head on main.

Files Patch % Lines
src/user-event/utils/warn-about-real-timers.ts 50.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1571 +/- ## ========================================== + Coverage 95.51% 95.61% +0.09% ========================================== Files 99 99 Lines 5400 5404 +4 Branches 857 865 +8 ========================================== + Hits 5158 5167 +9 + Misses 242 237 -5 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

JoseLion commented 6 months ago

@mdjastrzebski I think Codecov might be using a cached version of the coverage report or something like that. When I generate the report, I see that src/user-event/utils/warn-about-real-timers.ts is now 100% covered, but Codecov shows 50%, wdyt? 🤔

image

image

mdjastrzebski commented 6 months ago

This PR has been released in RNTL v12.4.4! 🎉