Skip to content

chore: add test to ensure it is possible to trigger native event #1114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/__tests__/fireEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,53 @@ test('has only onMove', () => {
});
expect(handleDrag).toHaveBeenCalled();
});

// Those events ideally should be triggered through `fireEvent.scroll`, but they are handled at the
// native level, so we need to support manually triggering them
describe('native events', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
describe('native events', () => {
describe('native event support', () => {

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should actually use host component event support instead, as by design we do not support "native" events.

test('triggers onScrollBeginDrag', () => {
const onScrollBeginDragSpy = jest.fn();
const { getByTestId } = render(
<ScrollView testID="test-id" onScrollBeginDrag={onScrollBeginDragSpy} />
);

fireEvent(getByTestId('test-id'), 'onScrollBeginDrag');
expect(onScrollBeginDragSpy).toHaveBeenCalled();
});

test('triggers onScrollEndDrag', () => {
const onScrollEndDragSpy = jest.fn();
const { getByTestId } = render(
<ScrollView testID="test-id" onScrollEndDrag={onScrollEndDragSpy} />
);

fireEvent(getByTestId('test-id'), 'onScrollEndDrag');
expect(onScrollEndDragSpy).toHaveBeenCalled();
});

test('triggers onMomentumScrollBegin', () => {
const onMomentumScrollBeginSpy = jest.fn();
const { getByTestId } = render(
<ScrollView
testID="test-id"
onMomentumScrollBegin={onMomentumScrollBeginSpy}
/>
);

fireEvent(getByTestId('test-id'), 'onMomentumScrollBegin');
expect(onMomentumScrollBeginSpy).toHaveBeenCalled();
});

test('triggers onMomentumScrollEnd', () => {
const onMomentumScrollEndSpy = jest.fn();
const { getByTestId } = render(
<ScrollView
testID="test-id"
onMomentumScrollEnd={onMomentumScrollEndSpy}
/>
);

fireEvent(getByTestId('test-id'), 'onMomentumScrollEnd');
expect(onMomentumScrollEndSpy).toHaveBeenCalled();
});
});