-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvitest.setup.tsx
More file actions
133 lines (117 loc) · 3.38 KB
/
vitest.setup.tsx
File metadata and controls
133 lines (117 loc) · 3.38 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import "@testing-library/jest-dom/vitest";
import { afterAll, beforeAll, vi } from "vitest";
// Suppress unhandled rejection warnings from parallel Promise.all retry loops
// These occur when testing error scenarios with parallel async operations
// where one promise rejects and the other's retry loop continues
const originalUnhandledRejection = process.listeners("unhandledRejection");
beforeAll(() => {
process.removeAllListeners("unhandledRejection");
process.on("unhandledRejection", () => {
// Silently ignore unhandled rejections in tests
});
});
afterAll(() => {
process.removeAllListeners("unhandledRejection");
for (const listener of originalUnhandledRejection) {
process.on(
"unhandledRejection",
listener as NodeJS.UnhandledRejectionListener,
);
}
});
// Mock next/navigation
vi.mock("next/navigation", () => ({
useRouter: () => ({
push: vi.fn(),
replace: vi.fn(),
prefetch: vi.fn(),
back: vi.fn(),
forward: vi.fn(),
refresh: vi.fn(),
}),
useSearchParams: () => new URLSearchParams(),
usePathname: () => "/",
useParams: () => ({}),
}));
// Mock next/image
vi.mock("next/image", () => ({
default: ({ src, alt, ...props }: { src: string; alt: string }) => {
// biome-ignore lint/a11y/useAltText: alt is passed via props
return <img src={src} alt={alt} {...props} />;
},
}));
// Mock @solana/react-hooks
vi.mock("@solana/react-hooks", () => ({
useWalletConnection: vi.fn(() => ({
connectors: [],
connect: vi.fn(),
disconnect: vi.fn(),
wallet: null,
status: "disconnected",
})),
SolanaProvider: ({ children }: { children: React.ReactNode }) => children,
}));
// Mock @solana/client
vi.mock("@solana/client", () => ({
createClient: vi.fn(() => ({})),
autoDiscover: vi.fn(() => []),
}));
// Mock @shelby-protocol/sdk/browser
vi.mock("@shelby-protocol/sdk/browser", () => ({
ShelbyClient: vi.fn().mockImplementation(() => ({
fundAccountWithShelbyUSD: vi.fn().mockResolvedValue({}),
fundAccountWithAPT: vi.fn().mockResolvedValue({}),
})),
}));
// Mock @shelby-protocol/solana-kit/react
vi.mock("@shelby-protocol/solana-kit/react", () => ({
useStorageAccount: vi.fn(() => ({
storageAccountAddress: null,
signAndSubmitTransaction: vi.fn(),
})),
Network: {
SHELBYNET: "shelbynet",
},
}));
// Mock @shelby-protocol/react
vi.mock("@shelby-protocol/react", () => ({
useUploadBlobs: vi.fn(() => ({
mutateAsync: vi.fn().mockResolvedValue({}),
isPending: false,
})),
}));
// Mock sonner
vi.mock("sonner", () => ({
toast: {
success: vi.fn(),
error: vi.fn(),
info: vi.fn(),
warning: vi.fn(),
},
}));
// Mock react-confetti
vi.mock("react-confetti", () => ({
default: () => <div data-testid="confetti" />,
}));
// Mock react-dom createPortal
vi.mock("react-dom", async () => {
const actual = await vi.importActual("react-dom");
return {
...actual,
createPortal: (children: React.ReactNode) => children,
};
});
// Mock navigator.clipboard
const mockClipboard = {
writeText: vi.fn().mockResolvedValue(undefined),
readText: vi.fn().mockResolvedValue(""),
};
Object.defineProperty(navigator, "clipboard", {
value: mockClipboard,
writable: true,
configurable: true,
});
// Mock window.scrollIntoView
Element.prototype.scrollIntoView = vi.fn();
// Make sure userEvent can use the clipboard
global.navigator.clipboard = mockClipboard as unknown as Clipboard;