Skip to content

Conversation

@JoseLion
Copy link
Contributor

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
Copy link

codecov bot commented Mar 14, 2024

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 ⚠️
Additional details and impacted files
@@ 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 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JoseLion
Copy link
Contributor Author

JoseLion commented Mar 17, 2024

@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

Copy link
Member

@mdjastrzebski mdjastrzebski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you for your effort 🚀

@mdjastrzebski mdjastrzebski merged commit b4d264f into callstack:main Mar 18, 2024
@mdjastrzebski
Copy link
Member

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

@JoseLion JoseLion deleted the fix/user-event-decouple-jest branch March 18, 2024 20:17
github-merge-queue bot referenced this pull request in valora-xyz/wallet Apr 1, 2024
….5 (#5196) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@testing-library/react-native](https://callstack.github.io/react-native-testing-library) ([source](https://togithub.com/callstack/react-native-testing-library)) | [`^12.4.3` -> `^12.4.5`](https://renovatebot.com/diffs/npm/@testing-library%2freact-native/12.4.3/12.4.5) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@testing-library%2freact-native/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@testing-library%2freact-native/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@testing-library%2freact-native/12.4.3/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@testing-library%2freact-native/12.4.3/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>callstack/react-native-testing-library (@&#8203;testing-library/react-native)</summary> ### [`v12.4.5`](https://togithub.com/callstack/react-native-testing-library/releases/tag/v12.4.5) [Compare Source](https://togithub.com/callstack/react-native-testing-library/compare/v12.4.4...v12.4.5) #### RNTL 12.4.5 (2024-03-28) ##### Bugfixes - `findBy*` timeout with detached screen by [@&#8203;mdjastrzebski](https://togithub.com/mdjastrzebski) in [https://github.com/callstack/react-native-testing-library/pull/1576](https://togithub.com/callstack/react-native-testing-library/pull/1576) ##### Other - docs: update docs about eslint rule by [@&#8203;mdjastrzebski](https://togithub.com/mdjastrzebski) in [https://github.com/callstack/react-native-testing-library/pull/1578](https://togithub.com/callstack/react-native-testing-library/pull/1578) **Full Changelog**: callstack/react-native-testing-library@v12.4.4...v12.4.5 ### [`v12.4.4`](https://togithub.com/callstack/react-native-testing-library/releases/tag/v12.4.4) [Compare Source](https://togithub.com/callstack/react-native-testing-library/compare/v12.4.3...v12.4.4) #### RNTL 12.4.4 (2024-03-18) ##### Bug Fixes - **user-event**: Decouple press events from Jest dependency by [@&#8203;JoseLion](https://togithub.com/JoseLion) in [https://github.com/callstack/react-native-testing-library/pull/1571](https://togithub.com/callstack/react-native-testing-library/pull/1571) #### New Contributors - [@&#8203;retyui](https://togithub.com/retyui) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1567](https://togithub.com/callstack/react-native-testing-library/pull/1567) - [@&#8203;donysukardi](https://togithub.com/donysukardi) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1569](https://togithub.com/callstack/react-native-testing-library/pull/1569) - [@&#8203;JoseLion](https://togithub.com/JoseLion) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1571](https://togithub.com/callstack/react-native-testing-library/pull/1571) **Full Changelog**: callstack/react-native-testing-library@v12.4.3...v12.4.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone America/Los_Angeles. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/valora-inc/wallet). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
github-merge-queue bot referenced this pull request in valora-xyz/wallet Apr 1, 2024
….5 (#5196) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@testing-library/react-native](https://callstack.github.io/react-native-testing-library) ([source](https://togithub.com/callstack/react-native-testing-library)) | [`^12.4.3` -> `^12.4.5`](https://renovatebot.com/diffs/npm/@testing-library%2freact-native/12.4.3/12.4.5) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@testing-library%2freact-native/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@testing-library%2freact-native/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@testing-library%2freact-native/12.4.3/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@testing-library%2freact-native/12.4.3/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>callstack/react-native-testing-library (@&#8203;testing-library/react-native)</summary> ### [`v12.4.5`](https://togithub.com/callstack/react-native-testing-library/releases/tag/v12.4.5) [Compare Source](https://togithub.com/callstack/react-native-testing-library/compare/v12.4.4...v12.4.5) #### RNTL 12.4.5 (2024-03-28) ##### Bugfixes - `findBy*` timeout with detached screen by [@&#8203;mdjastrzebski](https://togithub.com/mdjastrzebski) in [https://github.com/callstack/react-native-testing-library/pull/1576](https://togithub.com/callstack/react-native-testing-library/pull/1576) ##### Other - docs: update docs about eslint rule by [@&#8203;mdjastrzebski](https://togithub.com/mdjastrzebski) in [https://github.com/callstack/react-native-testing-library/pull/1578](https://togithub.com/callstack/react-native-testing-library/pull/1578) **Full Changelog**: callstack/react-native-testing-library@v12.4.4...v12.4.5 ### [`v12.4.4`](https://togithub.com/callstack/react-native-testing-library/releases/tag/v12.4.4) [Compare Source](https://togithub.com/callstack/react-native-testing-library/compare/v12.4.3...v12.4.4) #### RNTL 12.4.4 (2024-03-18) ##### Bug Fixes - **user-event**: Decouple press events from Jest dependency by [@&#8203;JoseLion](https://togithub.com/JoseLion) in [https://github.com/callstack/react-native-testing-library/pull/1571](https://togithub.com/callstack/react-native-testing-library/pull/1571) #### New Contributors - [@&#8203;retyui](https://togithub.com/retyui) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1567](https://togithub.com/callstack/react-native-testing-library/pull/1567) - [@&#8203;donysukardi](https://togithub.com/donysukardi) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1569](https://togithub.com/callstack/react-native-testing-library/pull/1569) - [@&#8203;JoseLion](https://togithub.com/JoseLion) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1571](https://togithub.com/callstack/react-native-testing-library/pull/1571) **Full Changelog**: callstack/react-native-testing-library@v12.4.3...v12.4.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone America/Los_Angeles. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/valora-inc/wallet). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
shottah referenced this pull request in Kolektivo/Kolektivo-Mobile-App May 15, 2024
….5 (valora-xyz#5196) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@testing-library/react-native](https://callstack.github.io/react-native-testing-library) ([source](https://togithub.com/callstack/react-native-testing-library)) | [`^12.4.3` -> `^12.4.5`](https://renovatebot.com/diffs/npm/@testing-library%2freact-native/12.4.3/12.4.5) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@testing-library%2freact-native/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@testing-library%2freact-native/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@testing-library%2freact-native/12.4.3/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@testing-library%2freact-native/12.4.3/12.4.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>callstack/react-native-testing-library (@&#8203;testing-library/react-native)</summary> ### [`v12.4.5`](https://togithub.com/callstack/react-native-testing-library/releases/tag/v12.4.5) [Compare Source](https://togithub.com/callstack/react-native-testing-library/compare/v12.4.4...v12.4.5) #### RNTL 12.4.5 (2024-03-28) ##### Bugfixes - `findBy*` timeout with detached screen by [@&#8203;mdjastrzebski](https://togithub.com/mdjastrzebski) in [https://github.com/callstack/react-native-testing-library/pull/1576](https://togithub.com/callstack/react-native-testing-library/pull/1576) ##### Other - docs: update docs about eslint rule by [@&#8203;mdjastrzebski](https://togithub.com/mdjastrzebski) in [https://github.com/callstack/react-native-testing-library/pull/1578](https://togithub.com/callstack/react-native-testing-library/pull/1578) **Full Changelog**: callstack/react-native-testing-library@v12.4.4...v12.4.5 ### [`v12.4.4`](https://togithub.com/callstack/react-native-testing-library/releases/tag/v12.4.4) [Compare Source](https://togithub.com/callstack/react-native-testing-library/compare/v12.4.3...v12.4.4) #### RNTL 12.4.4 (2024-03-18) ##### Bug Fixes - **user-event**: Decouple press events from Jest dependency by [@&#8203;JoseLion](https://togithub.com/JoseLion) in [https://github.com/callstack/react-native-testing-library/pull/1571](https://togithub.com/callstack/react-native-testing-library/pull/1571) #### New Contributors - [@&#8203;retyui](https://togithub.com/retyui) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1567](https://togithub.com/callstack/react-native-testing-library/pull/1567) - [@&#8203;donysukardi](https://togithub.com/donysukardi) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1569](https://togithub.com/callstack/react-native-testing-library/pull/1569) - [@&#8203;JoseLion](https://togithub.com/JoseLion) made their first contribution in [https://github.com/callstack/react-native-testing-library/pull/1571](https://togithub.com/callstack/react-native-testing-library/pull/1571) **Full Changelog**: callstack/react-native-testing-library@v12.4.3...v12.4.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone America/Los_Angeles. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/valora-inc/wallet). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants