-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest.setup.ts
43 lines (38 loc) · 1.05 KB
/
vitest.setup.ts
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
import { expect, afterEach, vi } from 'vitest';
import { cleanup } from '@testing-library/react';
// پاکسازی بعد از هر تست
afterEach(() => {
cleanup();
vi.clearAllMocks();
});
// تنظیم matchMedia برای تستها
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
// تعریف matcher های سفارشی
interface CustomMatchers<R = unknown> {
toBeInTheDocument(): R;
}
expect.extend({
toBeInTheDocument(received) {
const pass = received != null && received !== false;
return {
message: () => `expected ${received} ${pass ? 'not ' : ''}to be in the document`,
pass,
};
},
});
declare module 'vitest' {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}