react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

[v4] | [v2] Issue in resolving the test case for BottomSheetTextInput.

Open Ekaanth opened this issue 2 years ago • 4 comments

While trying to provide the test cases for the application I have been having difficulty mocking the call for BottomSheetTextInput. I'm using the initial mock that was provided in the earlier version (Thanks a lot for that):

I try to mock for the BottomSheetTextInput something like this:

jest.mock('@gorhom/bottom-sheet', () => {
  const MockBottomSheet = require('@gorhom/bottom-sheet/mock');
  const originalModule = jest.requireActual('@gorhom/bottom-sheet');

  return {
    __esModule: true,
    BottomSheetTextInput: originalModule.BottomSheetTextInput,
    ...MockBottomSheet,
  };
});

still facing an issue of thrown: "'useBottomSheetInternal' cannot be used out of the BottomSheet!" Which I'm unable to resolve. It would be amazing if you can look into this issue by providing a mock implementation for this problem.

Environment info

Library Version
@gorhom/bottom-sheet ^4.3.1
react-native 0.67.3
react-native 17.0.2
react-native-gesture-handler ^2.4.2

Steps To Reproduce

  1. Implement the bottom sheets component and it contains bottomsheetinputtext.

Describe what you expected to happen:

  1. resolving the issue that I'm getting for bottom sheet test case.

Reproducible sample code

Ekaanth avatar Jun 22 '22 11:06 Ekaanth

I am also facing same issue

banisetticn avatar Jun 27 '22 09:06 banisetticn

Any update on this issue?

Ekaanth avatar Jul 04 '22 12:07 Ekaanth

Following @pedrorestrepo's comment here, this is what I did to get the mock working:

import mockBottomSheet from '@gorhom/bottom-sheet/mock';

jest.mock('@gorhom/bottom-sheet', () => ({
  ...mockBottomSheet,
  __esModule: true,
}));

developius avatar Jul 15 '22 00:07 developius

@developius I do mock the same way right now, but I'm getting an error when I have the sheets that use BottomSheetTextInput. I t would be nice that BottomSheetTextInput is included in the mockup.

Ekaanth avatar Jul 15 '22 08:07 Ekaanth

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 14 '22 09:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Aug 19 '22 09:08 github-actions[bot]

Hi guys, Hi @Ekaanth, Ekaanth I'm still facing the same issue? any helps? Thank you guys so much. Really appreciated!

Screenshot 2023-09-26 at 17 28 23 Screenshot 2023-09-26 at 17 29 44

vdr-mm-quan avatar Sep 26 '23 10:09 vdr-mm-quan

Hi @vdr-mm-quan, if you're still looking for a solution, you can use this mock instead of the basic one:

jest.mock('@gorhom/bottom-sheet', () => {
  const { ScrollView, TextInput } = jest.requireActual('react-native')

  return ({
    ...require('@gorhom/bottom-sheet/mock'),
    __esModule: true,
    BottomSheetScrollView: ScrollView,
    BottomSheetTextInput: TextInput
  })
})

avencat avatar Oct 16 '23 10:10 avencat