forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmocks.js
More file actions
39 lines (32 loc) · 788 Bytes
/
Copy pathmocks.js
File metadata and controls
39 lines (32 loc) · 788 Bytes
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
import { vi } from 'vitest';
export function createMockFunction(impl) {
const fn = vi.fn();
if (impl) fn.mockImplementation(impl);
return fn;
}
export function createMockModule(shape) {
const mock = {};
for (const [key, value] of Object.entries(shape)) {
mock[key] = typeof value === 'function' ? createMockFunction(value) : value;
}
return mock;
}
export function createRequest({ body = {}, params = {}, query = {}, headers = {} } = {}) {
return {
body,
params,
query,
headers,
get(name) {
return headers[name.toLowerCase()];
},
};
}
export function createResponse() {
const res = {};
res.status = vi.fn(() => res);
res.json = vi.fn(() => res);
res.send = vi.fn(() => res);
res.set = vi.fn(() => res);
return res;
}