-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.setup.js
More file actions
62 lines (59 loc) · 1.7 KB
/
jest.setup.js
File metadata and controls
62 lines (59 loc) · 1.7 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
// Mock native modules
jest.mock('./src/NativeSheet', () => ({
__esModule: true,
default: {
viewportSize: jest.fn(() => ({ width: 375, height: 812 })),
dismissAll: jest.fn(),
dismissPresented: jest.fn(),
getConstants: jest.fn(() => ({
insets: { top: 44, bottom: 34 },
})),
},
}));
jest.mock('./src/SheetViewNativeComponent', () => {
const React = require('react');
return {
__esModule: true,
default: React.forwardRef((props, ref) => {
// Simulate native dismiss behavior by calling onSheetDismiss after a short delay
React.useImperativeHandle(ref, () => ({
dismiss: () => {
setTimeout(() => {
props.onSheetDismiss?.();
}, 50);
},
}));
return React.createElement('SheetView', { ...props, ref });
}),
Commands: {
dismissSheet: jest.fn((ref) => {
// Trigger the dismiss callback after a short delay to simulate native behavior
if (ref?.current) {
setTimeout(() => {
// Access the props from the ref and call onSheetDismiss
const element = ref.current;
if (element && element.props && element.props.onSheetDismiss) {
element.props.onSheetDismiss();
}
}, 50);
}
}),
},
};
});
// Mock @gorhom/portal
jest.mock('@gorhom/portal', () => ({
Portal: ({ children }) => children,
PortalProvider: ({ children }) => children,
PortalHost: ({ children }) => children,
}));
// Suppress console logs during tests
global.console = {
...console,
// Uncomment to suppress console logs during tests
// log: jest.fn(),
// debug: jest.fn(),
// info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};