-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: RN Gesture Handler Pressable support (#1746)
- Loading branch information
1 parent
a9c056b
commit bd78a26
Showing
10 changed files
with
222 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'react-native-gesture-handler/jestSetup.js'; | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { Pressable } from 'react-native-gesture-handler'; | ||
|
||
import { fireEvent, render, screen, userEvent } from '..'; | ||
import { createEventLogger, getEventsNames } from '../test-utils'; | ||
|
||
test('fireEvent can invoke press events for RNGH Pressable', () => { | ||
const onPress = jest.fn(); | ||
const onPressIn = jest.fn(); | ||
const onPressOut = jest.fn(); | ||
const onLongPress = jest.fn(); | ||
|
||
render( | ||
<View> | ||
<Pressable | ||
testID="pressable" | ||
onPress={onPress} | ||
onPressIn={onPressIn} | ||
onPressOut={onPressOut} | ||
onLongPress={onLongPress} | ||
/> | ||
</View>, | ||
); | ||
|
||
const pressable = screen.getByTestId('pressable'); | ||
|
||
fireEvent.press(pressable); | ||
expect(onPress).toHaveBeenCalled(); | ||
|
||
fireEvent(pressable, 'pressIn'); | ||
expect(onPressIn).toHaveBeenCalled(); | ||
|
||
fireEvent(pressable, 'pressOut'); | ||
expect(onPressOut).toHaveBeenCalled(); | ||
|
||
fireEvent(pressable, 'longPress'); | ||
expect(onLongPress).toHaveBeenCalled(); | ||
}); | ||
|
||
test('userEvent can invoke press events for RNGH Pressable', async () => { | ||
const { events, logEvent } = createEventLogger(); | ||
const user = userEvent.setup(); | ||
|
||
render( | ||
<View> | ||
<Pressable | ||
testID="pressable" | ||
onPress={logEvent('press')} | ||
onPressIn={logEvent('pressIn')} | ||
onPressOut={logEvent('pressOut')} | ||
onLongPress={logEvent('longPress')} | ||
/> | ||
</View>, | ||
); | ||
|
||
const pressable = screen.getByTestId('pressable'); | ||
await user.press(pressable); | ||
expect(getEventsNames(events)).toEqual(['pressIn', 'pressOut', 'press']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.