-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
101 lines (95 loc) · 2.96 KB
/
jest.setup.js
File metadata and controls
101 lines (95 loc) · 2.96 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Mock AsyncStorage for Jest
jest.mock('@react-native-async-storage/async-storage', () => ({
__esModule: true,
default: {
getItem: jest.fn(() => Promise.resolve(null)),
setItem: jest.fn(() => Promise.resolve()),
removeItem: jest.fn(() => Promise.resolve()),
multiGet: jest.fn(() => Promise.resolve([])),
multiSet: jest.fn(() => Promise.resolve()),
},
}));
// Mock react-native-maps for Jest
jest.mock('react-native-maps', () => {
return {
__esModule: true,
default: 'MapView',
Marker: 'Marker',
Polygon: 'Polygon',
Circle: 'Circle',
Polyline: 'Polyline',
};
});
// Mock @shopify/react-native-skia for Jest
jest.mock('@shopify/react-native-skia', () => ({
Skia: {
Surface: {
MakeOffscreen: jest.fn(() => ({
getCanvas: jest.fn(() => ({
drawSvg: jest.fn(),
drawCircle: jest.fn(),
drawText: jest.fn(),
})),
flush: jest.fn(),
makeImageSnapshot: jest.fn(() => ({
makeNonTextureImage: jest.fn(() => ({
encodeToBase64: jest.fn(() => 'mockBase64Data'),
})),
})),
dispose: jest.fn(),
})),
},
SVG: {
MakeFromString: jest.fn(() => ({})),
},
Paint: jest.fn(() => ({
setColor: jest.fn(),
setAntiAlias: jest.fn(),
})),
Font: jest.fn(() => ({})),
Color: jest.fn((c) => c),
FontMgr: {
System: jest.fn(() => ({})),
},
},
ImageFormat: {
PNG: 0,
},
}));
// Mock expo-asset
jest.mock('expo-asset', () => ({
Asset: {
fromModule: jest.fn(() => ({
downloadAsync: jest.fn(() => Promise.resolve()),
localUri: 'file:///mock/asset.svg',
})),
},
}));
// Mock expo-file-system (new File/Directory/Paths API)
const mockFileInstances = {};
jest.mock('expo-file-system', () => {
const MockFile = jest.fn(function (...args) {
// Build a uri from constructor args
const parts = args.map(a => (a && a.uri) ? a.uri : String(a));
this.uri = parts.join('/').replace(/\/+/g, '/');
this.text = jest.fn(() => Promise.resolve('<svg><path d="M0,0"/></svg>'));
this.write = jest.fn();
this.exists = false;
mockFileInstances[this.uri] = this;
});
const MockDirectory = jest.fn(function (...args) {
const parts = args.map(a => (a && a.uri) ? a.uri : String(a));
this.uri = parts.join('/').replace(/\/+/g, '/');
this.exists = false;
this.create = jest.fn();
this.delete = jest.fn();
});
return {
File: MockFile,
Directory: MockDirectory,
Paths: {
cache: { uri: 'file:///mock/cache' },
document: { uri: 'file:///mock/document' },
},
};
});