-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathevent-handler.test.tsx
More file actions
61 lines (50 loc) · 2.43 KB
/
event-handler.test.tsx
File metadata and controls
61 lines (50 loc) · 2.43 KB
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
60
61
import * as React from 'react';
import { Text, View } from 'react-native';
import { render, screen } from '..';
import { getEventHandlerFromProps } from '../event-handler';
test('getEventHandler strict mode', async () => {
const onPress = jest.fn();
const testOnlyOnPress = jest.fn();
await 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(getEventHandlerFromProps(regular.props, 'press')).toBe(onPress);
expect(getEventHandlerFromProps(testOnly.props, 'press')).toBe(testOnlyOnPress);
expect(getEventHandlerFromProps(both.props, 'press')).toBe(onPress);
expect(getEventHandlerFromProps(regular.props, 'onPress')).toBe(undefined);
expect(getEventHandlerFromProps(testOnly.props, 'onPress')).toBe(undefined);
expect(getEventHandlerFromProps(both.props, 'onPress')).toBe(undefined);
});
test('getEventHandler loose mode', async () => {
const onPress = jest.fn();
const testOnlyOnPress = jest.fn();
await 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(getEventHandlerFromProps(regular.props, 'press', { loose: true })).toBe(onPress);
expect(getEventHandlerFromProps(testOnly.props, 'press', { loose: true })).toBe(testOnlyOnPress);
expect(getEventHandlerFromProps(both.props, 'press', { loose: true })).toBe(onPress);
expect(getEventHandlerFromProps(regular.props, 'onPress', { loose: true })).toBe(onPress);
expect(getEventHandlerFromProps(testOnly.props, 'onPress', { loose: true })).toBe(
testOnlyOnPress,
);
expect(getEventHandlerFromProps(both.props, 'onPress', { loose: true })).toBe(onPress);
});