-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
108 lines (97 loc) · 2.64 KB
/
jest.setup.js
File metadata and controls
108 lines (97 loc) · 2.64 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
// Global test setup for VibeFunder
import '@testing-library/jest-dom';
// Mock environment variables for tests
process.env.NODE_ENV = 'test';
process.env.NEXTAUTH_SECRET = 'test-secret-key-for-testing-only';
process.env.DATABASE_URL = process.env.TEST_DATABASE_URL || 'postgresql://test:test@localhost:5432/vibefunder_test';
// Mock Next.js router
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
pathname: '/',
query: {},
asPath: '/',
}),
useSearchParams: () => new URLSearchParams(),
usePathname: () => '/',
}));
// Mock fetch globally for API tests
// Note: Disabled for now to allow real API testing
// global.fetch = require('jest-fetch-mock');
// Console configuration for cleaner test output
const originalError = console.error;
const originalWarn = console.warn;
beforeAll(() => {
// Suppress known warnings during tests
console.error = (...args) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('Warning: ReactDOM.render is deprecated') ||
args[0].includes('Warning: componentWillReceiveProps') ||
args[0].includes('act() wrapped'))
) {
return;
}
originalError.call(console, ...args);
};
console.warn = (...args) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('OpenAI API key not configured') ||
args[0].includes('Could not read .env.local'))
) {
return;
}
originalWarn.call(console, ...args);
};
});
afterAll(() => {
console.error = originalError;
console.warn = originalWarn;
});
// Global test timeout
jest.setTimeout(30000);
// Mock OpenAI for tests that don't need real AI calls
jest.mock('openai', () => {
return jest.fn().mockImplementation(() => ({
images: {
generate: jest.fn().mockResolvedValue({
data: [{
url: 'https://example.com/test-image.png'
}]
})
}
}));
});
// Custom matchers
expect.extend({
toBeValidUrl(received) {
const pass = /^https?:\/\//.test(received);
if (pass) {
return {
message: () => `expected ${received} not to be a valid URL`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to be a valid URL`,
pass: false,
};
}
},
toHaveValidImageFormat(received) {
const pass = /\.(jpg|jpeg|png|gif|webp)$/i.test(received);
if (pass) {
return {
message: () => `expected ${received} not to have valid image format`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to have valid image format`,
pass: false,
};
}
}
});