|  | 
|  | 1 | +import * as React from 'react'; | 
|  | 2 | +import { Text, View } from 'react-native'; | 
|  | 3 | + | 
|  | 4 | +import { render, screen } from '..'; | 
|  | 5 | +import { getEventHandler } from '../event-handler'; | 
|  | 6 | + | 
|  | 7 | +test('getEventHandler strict mode', () => { | 
|  | 8 | +  const onPress = jest.fn(); | 
|  | 9 | +  const testOnlyOnPress = jest.fn(); | 
|  | 10 | + | 
|  | 11 | +  render( | 
|  | 12 | +    <View> | 
|  | 13 | +      <Text testID="regular" onPress={onPress} /> | 
|  | 14 | +      {/* @ts-expect-error Intentionally passing such props */} | 
|  | 15 | +      <View testID="testOnly" testOnly_onPress={testOnlyOnPress} /> | 
|  | 16 | +      {/* @ts-expect-error Intentionally passing such props */} | 
|  | 17 | +      <View testID="both" onPress={onPress} testOnly_onPress={testOnlyOnPress} /> | 
|  | 18 | +    </View>, | 
|  | 19 | +  ); | 
|  | 20 | + | 
|  | 21 | +  const regular = screen.getByTestId('regular'); | 
|  | 22 | +  const testOnly = screen.getByTestId('testOnly'); | 
|  | 23 | +  const both = screen.getByTestId('both'); | 
|  | 24 | + | 
|  | 25 | +  expect(getEventHandler(regular, 'press')).toBe(onPress); | 
|  | 26 | +  expect(getEventHandler(testOnly, 'press')).toBe(testOnlyOnPress); | 
|  | 27 | +  expect(getEventHandler(both, 'press')).toBe(onPress); | 
|  | 28 | + | 
|  | 29 | +  expect(getEventHandler(regular, 'onPress')).toBe(undefined); | 
|  | 30 | +  expect(getEventHandler(testOnly, 'onPress')).toBe(undefined); | 
|  | 31 | +  expect(getEventHandler(both, 'onPress')).toBe(undefined); | 
|  | 32 | +}); | 
|  | 33 | + | 
|  | 34 | +test('getEventHandler loose mode', () => { | 
|  | 35 | +  const onPress = jest.fn(); | 
|  | 36 | +  const testOnlyOnPress = jest.fn(); | 
|  | 37 | + | 
|  | 38 | +  render( | 
|  | 39 | +    <View> | 
|  | 40 | +      <Text testID="regular" onPress={onPress} /> | 
|  | 41 | +      {/* @ts-expect-error Intentionally passing such props */} | 
|  | 42 | +      <View testID="testOnly" testOnly_onPress={testOnlyOnPress} /> | 
|  | 43 | +      {/* @ts-expect-error Intentionally passing such props */} | 
|  | 44 | +      <View testID="both" onPress={onPress} testOnly_onPress={testOnlyOnPress} /> | 
|  | 45 | +    </View>, | 
|  | 46 | +  ); | 
|  | 47 | + | 
|  | 48 | +  const regular = screen.getByTestId('regular'); | 
|  | 49 | +  const testOnly = screen.getByTestId('testOnly'); | 
|  | 50 | +  const both = screen.getByTestId('both'); | 
|  | 51 | + | 
|  | 52 | +  expect(getEventHandler(regular, 'press', { loose: true })).toBe(onPress); | 
|  | 53 | +  expect(getEventHandler(testOnly, 'press', { loose: true })).toBe(testOnlyOnPress); | 
|  | 54 | +  expect(getEventHandler(both, 'press', { loose: true })).toBe(onPress); | 
|  | 55 | + | 
|  | 56 | +  expect(getEventHandler(regular, 'onPress', { loose: true })).toBe(onPress); | 
|  | 57 | +  expect(getEventHandler(testOnly, 'onPress', { loose: true })).toBe(testOnlyOnPress); | 
|  | 58 | +  expect(getEventHandler(both, 'onPress', { loose: true })).toBe(onPress); | 
|  | 59 | +}); | 
0 commit comments