forked from PalisadoesFoundation/talawa-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
61 lines (55 loc) · 1.7 KB
/
vitest.setup.ts
File metadata and controls
61 lines (55 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
import '@testing-library/jest-dom';
import { cleanup } from '@testing-library/react';
import { afterAll, afterEach, beforeAll, vi } from 'vitest';
// Simple console error handler for React 18 warnings
const originalError = console.error;
const originalWarn = console.warn;
const shouldSuppressError = (value: unknown): boolean => {
if (typeof value !== 'string') {
if (value instanceof Error) {
return shouldSuppressError(value.message);
}
return false;
}
return value.includes(
'Warning: ReactDOM.render is no longer supported in React 18.',
);
};
beforeAll(() => {
console.error = (...args: unknown[]) => {
if (args.some(shouldSuppressError)) {
return; // Suppress known React 18 warnings
}
originalError.call(console, ...args);
};
console.warn = (...args: unknown[]) => {
if (args.some(shouldSuppressError)) {
return;
}
originalWarn.call(console, ...args);
};
});
// Basic cleanup after each test
afterEach(() => {
cleanup();
vi.clearAllMocks();
});
// Global mocks for URL API (needed for file upload tests)
// TODO: Remove once test isolation is properly fixed in individual test files
global.URL.createObjectURL = vi.fn(() => 'mock-object-url');
global.URL.revokeObjectURL = vi.fn();
// Mock HTMLFormElement.prototype.requestSubmit for jsdom
// TODO: Remove once jsdom adds native support
if (typeof HTMLFormElement.prototype.requestSubmit === 'undefined') {
HTMLFormElement.prototype.requestSubmit = function () {
if (this.checkValidity()) {
this.dispatchEvent(
new Event('submit', { cancelable: true, bubbles: true }),
);
}
};
}
afterAll(() => {
console.error = originalError;
console.warn = originalWarn;
});