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