Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Import fireEvent conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Feb 22, 2022
1 parent 8503171 commit 1a760e4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/jestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { fireEvent } from '@testing-library/react-native';
import invariant from 'invariant';
import { DeviceEventEmitter } from 'react-native';
import { ReactTestInstance } from 'react-test-renderer';
Expand Down Expand Up @@ -60,6 +59,22 @@ import {
import { State } from './State';
import { hasProperty, withPrevAndCurrent } from './utils';

// load fireEvent conditionally, so RNGH may be used in setups without testing-library
let fireEvent = (
_element: ReactTestInstance,
_name: string,
..._data: any[]
) => {
// NOOP
};

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
fireEvent = require('@testing-library/react-native').fireEvent;
} catch (_e) {
// do nothing if not available
}

type GestureHandlerTestEvent<
TEventPayload extends Record<string, unknown> = Record<string, unknown>
> = (
Expand Down

0 comments on commit 1a760e4

Please sign in to comment.