react-native-bottom-sheet: [v4] Jest tests don't run (included a minimal reproduction)
Bug
I have a bigger project that uses this library quite heavily, but when including it in our jest testing suite I run into all kinds of errors.
I’ve made a minimal reproduction here: https://github.com/gersomvg/bug-bottom-sheet-jest
The error that I run into there isn’t exactly the same as the one I have in the bigger project, but I suspect they are related.
It looks like @gorhom/bottom-sheet doesn’t play nicely with gesture-handler and reanimated mocks.
Environment info
| Library | Version |
|---|---|
| @gorhom/bottom-sheet | 4.2.2 |
| react-native | 17.0.2 |
| react-native-reanimated | 2.8.0 |
| react-native-gesture-handler | 2.4.1 (tried 1.10.3 as well) |
Steps To Reproduce
- Clone this repo: https://github.com/gersomvg/bug-bottom-sheet-jest
- Follow the three steps in the readme
Describe what you expected to happen:
- The tests run without error
Reproducible sample code
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 17 (4 by maintainers)
Here’s what I did, works for me:
will work on a fix by this week
use this:
I have a screen with three
BottomSheetcomponents. When I run a test case, all of them are opened on debug tree and overlap a button that must be pressed. Do you have any tips regarding this mock, thus none of the components stay opened? @Alaa-BenAnd shouldn’t we render the children conditionally in the render functions of the mock?
I’ve expected the children of to sheet/modal not to be in the dom when the modal/sheet is not actually visible, what are you thought’s on this @gorhom ?
@gorhom seems like the issue with
toStringis fixed, but was getting the following error because of how thedefaultis imported and used in our codebase.Fixed it by adding
__esModuleto the jest mock so it handles thedefaultcorrectlyHi @gersomvg , did the release v4.3.0 fixes your issue ?
@gorhom Amazing! Let me know if there is anything I can help you with, for example testing fixes or adding more docs regarding jest/testing.
I can also try out any possible fixes on our bigger project, to see if it also solves the issues there, since we use a few more bottom-sheet hooks and components in that project.