-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathfire-event-debug.test.tsx
More file actions
69 lines (58 loc) · 2.24 KB
/
fire-event-debug.test.tsx
File metadata and controls
69 lines (58 loc) · 2.24 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
62
63
64
65
66
67
68
69
import * as React from 'react';
import { Pressable, Text, View } from 'react-native';
import { configure, fireEvent, render, screen } from '..';
import { _console } from '../helpers/logger';
beforeEach(() => {
jest.spyOn(_console, 'debug').mockImplementation(() => {});
jest.spyOn(_console, 'info').mockImplementation(() => {});
jest.spyOn(_console, 'warn').mockImplementation(() => {});
jest.spyOn(_console, 'error').mockImplementation(() => {});
});
test('should log warning when firing event on element without handler', () => {
render(
<View>
<Text>No handler</Text>
</View>,
);
fireEvent.press(screen.getByText('No handler'));
expect(_console.warn).toHaveBeenCalledTimes(1);
expect(jest.mocked(_console.warn).mock.calls[0][0]).toMatchInlineSnapshot(`
" ▲ Fire Event: no event handler for "press" event found on <Text>No handler</Text> or any of its ancestors.
"
`);
});
test('should log warning when firing event on single disabled element', () => {
render(
<View>
<Pressable onPress={() => {}} disabled>
<Text>Disabled button</Text>
</Pressable>
</View>,
);
fireEvent.press(screen.getByText('Disabled button'));
expect(_console.warn).toHaveBeenCalledTimes(1);
expect(jest.mocked(_console.warn).mock.calls[0][0]).toMatchInlineSnapshot(`
" ▲ Fire Event: no enabled event handler for "press" event found. Found disabled event handler(s) on:
- <Pressable disabled={true} /> (composite element)
"
`);
});
test('should log warning about multiple disabled handlers', () => {
render(
<View>
<Pressable testID="outer" onPress={() => {}} disabled>
<Pressable testID="inner" onPress={() => {}} disabled>
<Text>Nested disabled</Text>
</Pressable>
</Pressable>
</View>,
);
fireEvent.press(screen.getByText('Nested disabled'));
expect(_console.warn).toHaveBeenCalledTimes(1);
expect(jest.mocked(_console.warn).mock.calls[0][0]).toMatchInlineSnapshot(`
" ▲ Fire Event: no enabled event handler for "press" event found. Found disabled event handler(s) on:
- <Pressable disabled={true} testID="inner" /> (composite element)
- <Pressable disabled={true} testID="outer" /> (composite element)
"
`);
});