Skip to content

[0.80.0] Some __mocks__ files missing from the react-native package (repro updated) #51993

Closed

Description

@UNIDY2002

Description

When performing test with jest, it reports missing some mock components.

Log available at: https://github.com/thu-info-community/thu-info-app/actions/runs/15625085983/job/44017663763

    Cannot find module '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock' from '../../node_modules/react-native/jest/setup.js'

    Require stack:
      /home/runner/work/thu-info-app/thu-info-app/node_modules/react-native-gesture-handler/lib/commonjs/components/GestureComponents.js
      /home/runner/work/thu-info-app/thu-info-app/node_modules/react-native-gesture-handler/lib/commonjs/index.js
      src/ui/schedule/schedule.tsx
      src/components/Root.tsx
      src/App.tsx
      test/render.test.tsx

      32 | import {configSet, setCalendarConfig} from "../../redux/slices/config";
      33 | import {getStatusBarHeight} from "react-native-safearea-height";
    > 34 | import {GestureHandlerRootView, RefreshControl, ScrollView} from "react-native-gesture-handler";
         | ^
      35 | import {CalendarData, Semester} from "@thu-info/lib/src/models/schedule/calendar";
      36 |
      37 | const examBeginMap: {[key: string]: number} = {

      at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/index.js:868:11)
      at requireActual (../../node_modules/react-native/jest/setup.js:204:19)
      at Object.require [as RefreshControl] (../../node_modules/react-native/index.js:84:12)
      at Object.RefreshControl (../../node_modules/react-native-gesture-handler/lib/commonjs/components/GestureComponents.tsx:31:51)
      at Object.require (../../node_modules/react-native-gesture-handler/lib/commonjs/index.ts:97:1)
      at Object.require (src/ui/schedule/schedule.tsx:34:1)
      at Object.require (src/components/Root.tsx:10:1)
      at Object.require (src/App.tsx:11:1)
      at Object.require (test/render.test.tsx:5:1)

Steps to reproduce

  1. import {GestureHandlerRootView, RefreshControl, ScrollView} from "react-native-gesture-handler"
  2. yarn test

BTW, I think the issue should reproduce regardless using react-native-gesture-handler or not.

React Native Version

0.80.0

Affected Platforms

Other (please specify)

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.5
  CPU: (8) arm64 Apple M2
  Memory: 116.70 MB / 24.00 GB
  Shell:
    version: 3.7.1
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 20.19.2
    path: /var/folders/c0/3fm8z4hx4qsfnqhl0l_v34tm0000gn/T/yarn--1749783376193-0.5435812973456269/node
  Yarn:
    version: 1.22.19
    path: /var/folders/c0/3fm8z4hx4qsfnqhl0l_v34tm0000gn/T/yarn--1749783376193-0.5435812973456269/yarn
  npm:
    version: 10.8.2
    path: /opt/homebrew/opt/node@20/bin/npm
  Watchman:
    version: 2025.05.26.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.4
      - iOS 18.4
      - macOS 15.4
      - tvOS 18.4
      - visionOS 2.4
      - watchOS 11.4
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java: Not Found
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

Cannot find module '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock' from '../../node_modules/react-native/jest/setup.js'

    Require stack:
      /home/runner/work/thu-info-app/thu-info-app/node_modules/react-native-gesture-handler/lib/commonjs/components/GestureComponents.js
      /home/runner/work/thu-info-app/thu-info-app/node_modules/react-native-gesture-handler/lib/commonjs/index.js
      src/ui/schedule/schedule.tsx
      src/components/Root.tsx
      src/App.tsx
      test/render.test.tsx

      32 | import {configSet, setCalendarConfig} from "../../redux/slices/config";
      33 | import {getStatusBarHeight} from "react-native-safearea-height";
    > 34 | import {GestureHandlerRootView, RefreshControl, ScrollView} from "react-native-gesture-handler";
         | ^
      35 | import {CalendarData, Semester} from "@thu-info/lib/src/models/schedule/calendar";
      36 |
      37 | const examBeginMap: {[key: string]: number} = {

      at Resolver._throwModNotFoundError (../../node_modules/jest-resolve/build/index.js:868:11)
      at requireActual (../../node_modules/react-native/jest/setup.js:204:19)
      at Object.require [as RefreshControl] (../../node_modules/react-native/index.js:84:12)
      at Object.RefreshControl (../../node_modules/react-native-gesture-handler/lib/commonjs/components/GestureComponents.tsx:31:51)
      at Object.require (../../node_modules/react-native-gesture-handler/lib/commonjs/index.ts:97:1)
      at Object.require (src/ui/schedule/schedule.tsx:34:1)
      at Object.require (src/components/Root.tsx:10:1)
      at Object.require (src/App.tsx:11:1)
      at Object.require (test/render.test.tsx:5:1)

MANDATORY Reproducer

https://github.com/UNIDY2002/rn-80-mocks-repro

Screenshots and Videos

No response

Activity

  1. added
    Needs: Repro
    on Jun 13, 2025
  2. react-native-bot commented on Jun 13, 2025

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  3. changed the title [-][0.80.0] Some __mocks__ files missing from the react-native package[/-] [+][0.80.0] Some __mocks__ files missing from the react-native package (repro updated)[/+] on Jun 13, 2025
  4. UNIDY2002 commented on Jun 13, 2025

    @UNIDY2002
    ContributorAuthor

    @react-native-bot Repro has been updated

  5. added
    Needs: Attention
    and removed on Jun 13, 2025
  6. isekovanic commented on Jun 13, 2025

    @isekovanic

    +1 for this, it just came to my attention as well.

    For those of you who are stuck, I was able to resolve this by doing:

    /* jest-setup.js */
    // ... other jest setup stuff
    jest.mock('react-native/Libraries/Components/RefreshControl/RefreshControl', () => ({
      __esModule: true,
      default: require('./__mocks__/RefreshControlMock'),
    }));
    

    and then adding:

    /* __mocks__/RefreshControlMock.js */
    const { View } = require('react-native');
    module.exports = View;
    

    at the root of the repository.

    The reason is that the mock no longer exists here as it is implied, but has been moved/removed (probably here, although it doesn't exist on 0.80).

  7. cipolleschi commented on Jun 13, 2025

    @cipolleschi
    Contributor

    potentially a duplicate of #51375

  8. cipolleschi commented on Jun 16, 2025

    @cipolleschi
    Contributor

    I also surfaced the issue to our Developer Experience team. Hopefully we can find a solution soon.

  9. UNIDY2002 commented on Jul 3, 2025

    @UNIDY2002
    ContributorAuthor

    This issue is fixed in 0.80.1. Thanks all :)

  10. troZee commented on Jul 17, 2025

    @troZee
    Contributor

    The RN 80.1 did not fix my issue

     FAIL   @shared/ui  packages/shared/ui/src/hooks/__tests__/useAndroidHardwareBackPress.test.ts
      ● Test suite failed to run
    
        Cannot find module 'react-native/Libraries/Utilities/__mocks__/BackHandler' from 'src/hooks/__tests__/useAndroidHardwareBackPress.test.ts'
    
           9 | jest.mock('react-native/Libraries/Utilities/BackHandler', () =>
          10 |   // eslint-disable-next-line jest/no-mocks-import
        > 11 |   require('react-native/Libraries/Utilities/__mocks__/BackHandler'),
             |   ^
          12 | );
    

    Inside my node_modules, I am not able to find this path react-native/Libraries/Utilities/__mocks__/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionNeeds: Repro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions