@jmruthers/pace-core 0.5.117 → 0.5.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DataTable-ZOAKQ3SU.js → DataTable-BQYGKVHR.js} +6 -6
- package/dist/{UnifiedAuthProvider-YFN7YGVN.js → UnifiedAuthProvider-UACKFATV.js} +3 -3
- package/dist/{chunk-XN2LYHDI.js → chunk-B4GZ2BXO.js} +27 -8
- package/dist/{chunk-XN2LYHDI.js.map → chunk-B4GZ2BXO.js.map} +1 -1
- package/dist/{chunk-KA3PSVNV.js → chunk-BHWIUEYH.js} +2 -1
- package/dist/chunk-BHWIUEYH.js.map +1 -0
- package/dist/{chunk-LFS45U62.js → chunk-CGURJ27Z.js} +2 -2
- package/dist/{chunk-PHDAXDHB.js → chunk-D6BOFXYR.js} +3 -3
- package/dist/{chunk-2LM4QQGH.js → chunk-F7COHU5B.js} +8 -8
- package/dist/{chunk-P3PUOL6B.js → chunk-FKFHZUGF.js} +4 -4
- package/dist/{chunk-UKZWNQMB.js → chunk-NP5VABFV.js} +4 -4
- package/dist/{chunk-O3FTRYEU.js → chunk-NZ32EONV.js} +2 -2
- package/dist/{chunk-ECOVPXYS.js → chunk-RIEJGKD3.js} +4 -4
- package/dist/{chunk-IZXS7RZK.js → chunk-TDNI6ZWL.js} +5 -5
- package/dist/{chunk-VN3OOE35.js → chunk-ZYJ6O5CA.js} +2 -2
- package/dist/components.js +8 -8
- package/dist/hooks.js +7 -7
- package/dist/index.js +11 -11
- package/dist/providers.js +2 -2
- package/dist/rbac/index.js +7 -7
- package/dist/utils.js +1 -1
- package/docs/api/classes/ColumnFactory.md +1 -1
- package/docs/api/classes/ErrorBoundary.md +1 -1
- package/docs/api/classes/InvalidScopeError.md +1 -1
- package/docs/api/classes/MissingUserContextError.md +1 -1
- package/docs/api/classes/OrganisationContextRequiredError.md +1 -1
- package/docs/api/classes/PermissionDeniedError.md +1 -1
- package/docs/api/classes/PublicErrorBoundary.md +1 -1
- package/docs/api/classes/RBACAuditManager.md +1 -1
- package/docs/api/classes/RBACCache.md +1 -1
- package/docs/api/classes/RBACEngine.md +1 -1
- package/docs/api/classes/RBACError.md +1 -1
- package/docs/api/classes/RBACNotInitializedError.md +1 -1
- package/docs/api/classes/SecureSupabaseClient.md +1 -1
- package/docs/api/classes/StorageUtils.md +1 -1
- package/docs/api/enums/FileCategory.md +1 -1
- package/docs/api/interfaces/AggregateConfig.md +1 -1
- package/docs/api/interfaces/ButtonProps.md +1 -1
- package/docs/api/interfaces/CardProps.md +1 -1
- package/docs/api/interfaces/ColorPalette.md +1 -1
- package/docs/api/interfaces/ColorShade.md +1 -1
- package/docs/api/interfaces/DataAccessRecord.md +1 -1
- package/docs/api/interfaces/DataRecord.md +1 -1
- package/docs/api/interfaces/DataTableAction.md +1 -1
- package/docs/api/interfaces/DataTableColumn.md +1 -1
- package/docs/api/interfaces/DataTableProps.md +1 -1
- package/docs/api/interfaces/DataTableToolbarButton.md +1 -1
- package/docs/api/interfaces/EmptyStateConfig.md +1 -1
- package/docs/api/interfaces/EnhancedNavigationMenuProps.md +1 -1
- package/docs/api/interfaces/EventAppRoleData.md +1 -1
- package/docs/api/interfaces/FileDisplayProps.md +1 -1
- package/docs/api/interfaces/FileMetadata.md +1 -1
- package/docs/api/interfaces/FileReference.md +1 -1
- package/docs/api/interfaces/FileSizeLimits.md +1 -1
- package/docs/api/interfaces/FileUploadOptions.md +1 -1
- package/docs/api/interfaces/FileUploadProps.md +1 -1
- package/docs/api/interfaces/FooterProps.md +1 -1
- package/docs/api/interfaces/GrantEventAppRoleParams.md +1 -1
- package/docs/api/interfaces/InactivityWarningModalProps.md +1 -1
- package/docs/api/interfaces/InputProps.md +1 -1
- package/docs/api/interfaces/LabelProps.md +1 -1
- package/docs/api/interfaces/LoginFormProps.md +1 -1
- package/docs/api/interfaces/NavigationAccessRecord.md +1 -1
- package/docs/api/interfaces/NavigationContextType.md +1 -1
- package/docs/api/interfaces/NavigationGuardProps.md +1 -1
- package/docs/api/interfaces/NavigationItem.md +1 -1
- package/docs/api/interfaces/NavigationMenuProps.md +1 -1
- package/docs/api/interfaces/NavigationProviderProps.md +1 -1
- package/docs/api/interfaces/Organisation.md +1 -1
- package/docs/api/interfaces/OrganisationContextType.md +1 -1
- package/docs/api/interfaces/OrganisationMembership.md +1 -1
- package/docs/api/interfaces/OrganisationProviderProps.md +1 -1
- package/docs/api/interfaces/OrganisationSecurityError.md +1 -1
- package/docs/api/interfaces/PaceAppLayoutProps.md +1 -1
- package/docs/api/interfaces/PaceLoginPageProps.md +1 -1
- package/docs/api/interfaces/PageAccessRecord.md +1 -1
- package/docs/api/interfaces/PagePermissionContextType.md +1 -1
- package/docs/api/interfaces/PagePermissionGuardProps.md +1 -1
- package/docs/api/interfaces/PagePermissionProviderProps.md +1 -1
- package/docs/api/interfaces/PaletteData.md +1 -1
- package/docs/api/interfaces/PermissionEnforcerProps.md +1 -1
- package/docs/api/interfaces/ProtectedRouteProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryProps.md +1 -1
- package/docs/api/interfaces/PublicErrorBoundaryState.md +1 -1
- package/docs/api/interfaces/PublicLoadingSpinnerProps.md +1 -1
- package/docs/api/interfaces/PublicPageFooterProps.md +1 -1
- package/docs/api/interfaces/PublicPageHeaderProps.md +1 -1
- package/docs/api/interfaces/PublicPageLayoutProps.md +1 -1
- package/docs/api/interfaces/RBACConfig.md +1 -1
- package/docs/api/interfaces/RBACLogger.md +1 -1
- package/docs/api/interfaces/RevokeEventAppRoleParams.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterContextType.md +1 -1
- package/docs/api/interfaces/RoleBasedRouterProps.md +1 -1
- package/docs/api/interfaces/RoleManagementResult.md +1 -1
- package/docs/api/interfaces/RouteAccessRecord.md +1 -1
- package/docs/api/interfaces/RouteConfig.md +1 -1
- package/docs/api/interfaces/SecureDataContextType.md +1 -1
- package/docs/api/interfaces/SecureDataProviderProps.md +1 -1
- package/docs/api/interfaces/StorageConfig.md +1 -1
- package/docs/api/interfaces/StorageFileInfo.md +1 -1
- package/docs/api/interfaces/StorageFileMetadata.md +1 -1
- package/docs/api/interfaces/StorageListOptions.md +1 -1
- package/docs/api/interfaces/StorageListResult.md +1 -1
- package/docs/api/interfaces/StorageUploadOptions.md +1 -1
- package/docs/api/interfaces/StorageUploadResult.md +1 -1
- package/docs/api/interfaces/StorageUrlOptions.md +1 -1
- package/docs/api/interfaces/StyleImport.md +1 -1
- package/docs/api/interfaces/SwitchProps.md +1 -1
- package/docs/api/interfaces/ToastActionElement.md +1 -1
- package/docs/api/interfaces/ToastProps.md +1 -1
- package/docs/api/interfaces/UnifiedAuthContextType.md +1 -1
- package/docs/api/interfaces/UnifiedAuthProviderProps.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerOptions.md +1 -1
- package/docs/api/interfaces/UseInactivityTrackerReturn.md +1 -1
- package/docs/api/interfaces/UsePublicEventOptions.md +1 -1
- package/docs/api/interfaces/UsePublicEventReturn.md +1 -1
- package/docs/api/interfaces/UsePublicFileDisplayOptions.md +1 -1
- package/docs/api/interfaces/UsePublicFileDisplayReturn.md +1 -1
- package/docs/api/interfaces/UsePublicRouteParamsReturn.md +1 -1
- package/docs/api/interfaces/UseResolvedScopeOptions.md +1 -1
- package/docs/api/interfaces/UseResolvedScopeReturn.md +1 -1
- package/docs/api/interfaces/UserEventAccess.md +1 -1
- package/docs/api/interfaces/UserMenuProps.md +1 -1
- package/docs/api/interfaces/UserProfile.md +1 -1
- package/docs/api/modules.md +2 -2
- package/package.json +1 -1
- package/src/components/DataTable/__tests__/DataTableCore.test.tsx +697 -0
- package/src/components/DataTable/components/__tests__/EditableRow.test.tsx +544 -9
- package/src/components/DataTable/components/__tests__/UnifiedTableBody.test.tsx +1004 -0
- package/src/components/DataTable/utils/__tests__/a11yUtils.test.ts +612 -0
- package/src/components/DataTable/utils/__tests__/errorHandling.test.ts +266 -0
- package/src/components/DataTable/utils/__tests__/exportUtils.test.ts +455 -1
- package/src/hooks/__tests__/index.unit.test.ts +223 -0
- package/src/hooks/__tests__/useDataTablePerformance.unit.test.ts +748 -0
- package/src/hooks/__tests__/useEvents.unit.test.ts +249 -0
- package/src/hooks/__tests__/useFileDisplay.unit.test.ts +1060 -0
- package/src/hooks/__tests__/useFileUrl.unit.test.ts +958 -0
- package/src/hooks/__tests__/useFocusTrap.unit.test.tsx +540 -1
- package/src/hooks/__tests__/useIsMobile.unit.test.ts +205 -5
- package/src/hooks/__tests__/useKeyboardShortcuts.unit.test.ts +616 -1
- package/src/hooks/__tests__/useOrganisations.unit.test.ts +369 -0
- package/src/hooks/__tests__/usePerformanceMonitor.unit.test.ts +608 -0
- package/src/hooks/__tests__/useSecureDataAccess.unit.test.tsx +2 -0
- package/src/hooks/__tests__/useSessionRestoration.unit.test.tsx +372 -0
- package/src/hooks/__tests__/useToast.unit.test.tsx +431 -30
- package/src/hooks/useSecureDataAccess.test.ts +1 -0
- package/src/hooks/useSecureDataAccess.ts +43 -5
- package/src/rbac/audit-enhanced.ts +339 -0
- package/src/services/EventService.ts +1 -0
- package/src/services/__tests__/AuthService.test.ts +473 -0
- package/src/services/__tests__/EventService.test.ts +390 -0
- package/src/services/__tests__/InactivityService.test.ts +217 -0
- package/src/services/__tests__/OrganisationService.test.ts +371 -0
- package/dist/chunk-KA3PSVNV.js.map +0 -1
- package/src/components/DataTable/utils/debugTools.ts +0 -609
- package/src/rbac/testing/index.tsx +0 -340
- /package/dist/{DataTable-ZOAKQ3SU.js.map → DataTable-BQYGKVHR.js.map} +0 -0
- /package/dist/{UnifiedAuthProvider-YFN7YGVN.js.map → UnifiedAuthProvider-UACKFATV.js.map} +0 -0
- /package/dist/{chunk-LFS45U62.js.map → chunk-CGURJ27Z.js.map} +0 -0
- /package/dist/{chunk-PHDAXDHB.js.map → chunk-D6BOFXYR.js.map} +0 -0
- /package/dist/{chunk-2LM4QQGH.js.map → chunk-F7COHU5B.js.map} +0 -0
- /package/dist/{chunk-P3PUOL6B.js.map → chunk-FKFHZUGF.js.map} +0 -0
- /package/dist/{chunk-UKZWNQMB.js.map → chunk-NP5VABFV.js.map} +0 -0
- /package/dist/{chunk-O3FTRYEU.js.map → chunk-NZ32EONV.js.map} +0 -0
- /package/dist/{chunk-ECOVPXYS.js.map → chunk-RIEJGKD3.js.map} +0 -0
- /package/dist/{chunk-IZXS7RZK.js.map → chunk-TDNI6ZWL.js.map} +0 -0
- /package/dist/{chunk-VN3OOE35.js.map → chunk-ZYJ6O5CA.js.map} +0 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Error Handling Tests
|
|
3
|
+
* @package @jmruthers/pace-core
|
|
4
|
+
* @module Components/DataTable/Utils/__tests__
|
|
5
|
+
* @since 0.3.0
|
|
6
|
+
*
|
|
7
|
+
* Tests for error handling stubs. These are minimal implementations
|
|
8
|
+
* required by useDataTablePerformance.ts to provide a consistent API contract.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect } from 'vitest';
|
|
12
|
+
import {
|
|
13
|
+
DataTableError,
|
|
14
|
+
DataTableErrorType,
|
|
15
|
+
ErrorRecoveryManager,
|
|
16
|
+
MemoryMonitor,
|
|
17
|
+
CircuitBreaker,
|
|
18
|
+
safeExecute,
|
|
19
|
+
DEFAULT_FALLBACK_CONFIG,
|
|
20
|
+
type FallbackConfig,
|
|
21
|
+
} from '../errorHandling';
|
|
22
|
+
|
|
23
|
+
describe('[unit] errorHandling', () => {
|
|
24
|
+
describe('DataTableErrorType', () => {
|
|
25
|
+
it('contains all expected error types', () => {
|
|
26
|
+
expect(DataTableErrorType.VIRTUALIZATION).toBe('virtualization');
|
|
27
|
+
expect(DataTableErrorType.SEARCH_INDEX).toBe('search_index');
|
|
28
|
+
expect(DataTableErrorType.DATA_CHUNK).toBe('data_chunk');
|
|
29
|
+
expect(DataTableErrorType.SERVER_FETCH).toBe('server_fetch');
|
|
30
|
+
expect(DataTableErrorType.MEMORY).toBe('memory');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('DataTableError', () => {
|
|
35
|
+
it('creates error with message and type', () => {
|
|
36
|
+
const error = new DataTableError('Test error', DataTableErrorType.VIRTUALIZATION);
|
|
37
|
+
|
|
38
|
+
expect(error.message).toBe('Test error');
|
|
39
|
+
expect(error.type).toBe(DataTableErrorType.VIRTUALIZATION);
|
|
40
|
+
expect(error.name).toBe('DataTableError');
|
|
41
|
+
expect(error.recoverable).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('creates error with custom recoverable flag', () => {
|
|
45
|
+
const error = new DataTableError('Test error', DataTableErrorType.MEMORY, false);
|
|
46
|
+
|
|
47
|
+
expect(error.recoverable).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('defaults recoverable to true', () => {
|
|
51
|
+
const error = new DataTableError('Test error', DataTableErrorType.SERVER_FETCH);
|
|
52
|
+
|
|
53
|
+
expect(error.recoverable).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('extends Error class', () => {
|
|
57
|
+
const error = new DataTableError('Test error', DataTableErrorType.DATA_CHUNK);
|
|
58
|
+
|
|
59
|
+
expect(error).toBeInstanceOf(Error);
|
|
60
|
+
expect(error.stack).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('handles all error types', () => {
|
|
64
|
+
const types = [
|
|
65
|
+
DataTableErrorType.VIRTUALIZATION,
|
|
66
|
+
DataTableErrorType.SEARCH_INDEX,
|
|
67
|
+
DataTableErrorType.DATA_CHUNK,
|
|
68
|
+
DataTableErrorType.SERVER_FETCH,
|
|
69
|
+
DataTableErrorType.MEMORY,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
types.forEach((type) => {
|
|
73
|
+
const error = new DataTableError('Test', type);
|
|
74
|
+
expect(error.type).toBe(type);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('DEFAULT_FALLBACK_CONFIG', () => {
|
|
80
|
+
it('has enabled set to false', () => {
|
|
81
|
+
expect(DEFAULT_FALLBACK_CONFIG.enabled).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('matches FallbackConfig interface', () => {
|
|
85
|
+
const config: FallbackConfig = DEFAULT_FALLBACK_CONFIG;
|
|
86
|
+
expect(config).toBeDefined();
|
|
87
|
+
expect(typeof config.enabled).toBe('boolean');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('ErrorRecoveryManager', () => {
|
|
92
|
+
it('creates instance with config', () => {
|
|
93
|
+
const config: FallbackConfig = { enabled: false };
|
|
94
|
+
const manager = new ErrorRecoveryManager(config);
|
|
95
|
+
|
|
96
|
+
expect(manager).toBeInstanceOf(ErrorRecoveryManager);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('handles error and returns recovery result', async () => {
|
|
100
|
+
const manager = new ErrorRecoveryManager(DEFAULT_FALLBACK_CONFIG);
|
|
101
|
+
const error = new DataTableError('Test error', DataTableErrorType.VIRTUALIZATION);
|
|
102
|
+
|
|
103
|
+
const result = await manager.handleError(error);
|
|
104
|
+
|
|
105
|
+
expect(result).toEqual({ recovered: false, strategy: null });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('handles different error types', async () => {
|
|
109
|
+
const manager = new ErrorRecoveryManager(DEFAULT_FALLBACK_CONFIG);
|
|
110
|
+
|
|
111
|
+
const types = [
|
|
112
|
+
DataTableErrorType.VIRTUALIZATION,
|
|
113
|
+
DataTableErrorType.SEARCH_INDEX,
|
|
114
|
+
DataTableErrorType.DATA_CHUNK,
|
|
115
|
+
DataTableErrorType.SERVER_FETCH,
|
|
116
|
+
DataTableErrorType.MEMORY,
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
for (const type of types) {
|
|
120
|
+
const error = new DataTableError('Test', type);
|
|
121
|
+
const result = await manager.handleError(error);
|
|
122
|
+
expect(result).toEqual({ recovered: false, strategy: null });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('clears error log without throwing', () => {
|
|
127
|
+
const manager = new ErrorRecoveryManager(DEFAULT_FALLBACK_CONFIG);
|
|
128
|
+
|
|
129
|
+
expect(() => manager.clearErrorLog()).not.toThrow();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('MemoryMonitor', () => {
|
|
134
|
+
it('creates instance with threshold', () => {
|
|
135
|
+
const monitor = new MemoryMonitor(100);
|
|
136
|
+
|
|
137
|
+
expect(monitor).toBeInstanceOf(MemoryMonitor);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('creates instance with default threshold', () => {
|
|
141
|
+
const monitor = new MemoryMonitor();
|
|
142
|
+
|
|
143
|
+
expect(monitor).toBeInstanceOf(MemoryMonitor);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('returns zero for current usage', () => {
|
|
147
|
+
const monitor = new MemoryMonitor(100);
|
|
148
|
+
|
|
149
|
+
expect(monitor.getCurrentUsage()).toBe(0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('returns true for threshold check', () => {
|
|
153
|
+
const monitor = new MemoryMonitor(100);
|
|
154
|
+
|
|
155
|
+
expect(monitor.checkThreshold()).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('stops monitoring without throwing', () => {
|
|
159
|
+
const monitor = new MemoryMonitor(100);
|
|
160
|
+
|
|
161
|
+
expect(() => monitor.stopMonitoring()).not.toThrow();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('handles multiple threshold values', () => {
|
|
165
|
+
const monitors = [50, 100, 200, 500].map((threshold) => new MemoryMonitor(threshold));
|
|
166
|
+
|
|
167
|
+
monitors.forEach((monitor) => {
|
|
168
|
+
expect(monitor.getCurrentUsage()).toBe(0);
|
|
169
|
+
expect(monitor.checkThreshold()).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('CircuitBreaker', () => {
|
|
175
|
+
it('creates instance', () => {
|
|
176
|
+
const breaker = new CircuitBreaker();
|
|
177
|
+
|
|
178
|
+
expect(breaker).toBeInstanceOf(CircuitBreaker);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('returns false for isOpen()', () => {
|
|
182
|
+
const breaker = new CircuitBreaker();
|
|
183
|
+
|
|
184
|
+
expect(breaker.isOpen()).toBe(false);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('records success without throwing', () => {
|
|
188
|
+
const breaker = new CircuitBreaker();
|
|
189
|
+
|
|
190
|
+
expect(() => breaker.recordSuccess()).not.toThrow();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('records failure without throwing', () => {
|
|
194
|
+
const breaker = new CircuitBreaker();
|
|
195
|
+
|
|
196
|
+
expect(() => breaker.recordFailure()).not.toThrow();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('resets without throwing', () => {
|
|
200
|
+
const breaker = new CircuitBreaker();
|
|
201
|
+
|
|
202
|
+
expect(() => breaker.reset()).not.toThrow();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('handles multiple operations', () => {
|
|
206
|
+
const breaker = new CircuitBreaker();
|
|
207
|
+
|
|
208
|
+
expect(breaker.isOpen()).toBe(false);
|
|
209
|
+
breaker.recordSuccess();
|
|
210
|
+
breaker.recordFailure();
|
|
211
|
+
breaker.reset();
|
|
212
|
+
expect(breaker.isOpen()).toBe(false);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('safeExecute', () => {
|
|
217
|
+
it('returns function result when execution succeeds', () => {
|
|
218
|
+
const result = safeExecute(() => 42, 0);
|
|
219
|
+
|
|
220
|
+
expect(result).toBe(42);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('returns fallback when function throws', () => {
|
|
224
|
+
const result = safeExecute(() => {
|
|
225
|
+
throw new Error('Test error');
|
|
226
|
+
}, 'fallback');
|
|
227
|
+
|
|
228
|
+
expect(result).toBe('fallback');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('handles different return types', () => {
|
|
232
|
+
expect(safeExecute(() => 'success', 'fallback')).toBe('success');
|
|
233
|
+
expect(safeExecute(() => 123, 0)).toBe(123);
|
|
234
|
+
expect(safeExecute(() => true, false)).toBe(true);
|
|
235
|
+
expect(safeExecute(() => ({ key: 'value' }), {})).toEqual({ key: 'value' });
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('handles different fallback types', () => {
|
|
239
|
+
expect(safeExecute(() => {
|
|
240
|
+
throw new Error('Error');
|
|
241
|
+
}, 'string-fallback')).toBe('string-fallback');
|
|
242
|
+
|
|
243
|
+
expect(safeExecute(() => {
|
|
244
|
+
throw new Error('Error');
|
|
245
|
+
}, 999)).toBe(999);
|
|
246
|
+
|
|
247
|
+
expect(safeExecute(() => {
|
|
248
|
+
throw new Error('Error');
|
|
249
|
+
}, false)).toBe(false);
|
|
250
|
+
|
|
251
|
+
expect(safeExecute(() => {
|
|
252
|
+
throw new Error('Error');
|
|
253
|
+
}, { fallback: 'object' })).toEqual({ fallback: 'object' });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('handles null and undefined', () => {
|
|
257
|
+
expect(safeExecute(() => null, 'fallback')).toBeNull();
|
|
258
|
+
expect(safeExecute(() => {
|
|
259
|
+
throw new Error('Error');
|
|
260
|
+
}, null)).toBeNull();
|
|
261
|
+
|
|
262
|
+
expect(safeExecute(() => undefined, 'fallback')).toBeUndefined();
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|