test(fire-event): validate fireEvent.press invokes event handler on element

This commit is contained in:
Maciej Jastrzębski
2026-01-08 23:43:37 +01:00
parent 5dc0bb195d
commit 58254dfd3a
2 changed files with 18 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
import * as React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import { fireEvent, render, screen } from '..';
it('invokes event handler when firing event on element', async () => {
const onPressMock = jest.fn();
await render(
<TouchableOpacity onPress={onPressMock}>
<Text>Press me</Text>
</TouchableOpacity>,
);
await fireEvent.press(screen.getByText('Press me'));
expect(onPressMock).toHaveBeenCalledTimes(1);
});
+1
View File
@@ -9,3 +9,4 @@ test(queries/test-id): Validates getByTestId with exact:false option for partial
test(wait-for): Validates waitFor timeout behavior when expectation never passes - critical error handling users depend on when async conditions fail. Coverage: 55% statements (was 12%), 43.47% branches, 85.71% functions for wait-for.ts. Covered timeout error path and lastError handling. Uncovered: fake timers path, promise-returning expectations, onTimeout callback, timer switching errors.
test(wait-for-element-to-be-removed): Validates error when element is already removed at call time - critical error handling users depend on when misusing the API. Coverage: 61.9% statements (was 9.52%), 66.66% branches, 100% functions for wait-for-element-to-be-removed.ts. Covered isRemoved helper and initial validation error path. Uncovered: wait logic (lines 27-42).
test(render-hook): Validates renderHook with initial props and rerender functionality - critical API users depend on for testing React hooks with props. Coverage: 100% statements (was 5.66%), 85.71% branches, 100% functions for render-hook.tsx. Covered hook rendering, initialProps, rerender with new props. Uncovered: line 41 (options destructuring edge case).
test(fire-event): Validates fireEvent.press invokes event handler on element - critical API users depend on for testing user interactions. Coverage: 77.27% statements (was 33.33%), 53.33% branches, 87.5% functions for fire-event.ts. Covered main fireEvent function, findEventHandler traversal, handler invocation. Uncovered: isTouchResponder, isEventEnabled edge cases, setNativeStateIfNeeded, tryGetContentOffset.