d8a8931bc3
Mock @prisma/client globally in bun-setup.ts to allow unit tests to run without requiring the generated Prisma client. This improves test isolation and allows tests to pass even when prisma generate hasn't been run.
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
// Setup file for Bun test runner to provide DOM environment
|
|
import { JSDOM } from 'jsdom';
|
|
import { mock } from 'bun:test';
|
|
|
|
console.log('Loading bun-setup.ts...');
|
|
|
|
// Mock @prisma/client to avoid dependency on generated Prisma client
|
|
// This allows unit tests to run without requiring `prisma generate`
|
|
mock.module('@prisma/client', () => {
|
|
return {
|
|
PrismaClient: class MockPrismaClient {
|
|
$connect() {}
|
|
$disconnect() {}
|
|
$transaction() {}
|
|
}
|
|
};
|
|
});
|
|
|
|
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
|
|
url: 'http://localhost',
|
|
pretendToBeVisual: true,
|
|
});
|
|
|
|
(global as any).window = dom.window;
|
|
(global as any).document = dom.window.document;
|
|
(global as any).navigator = dom.window.navigator;
|
|
|
|
console.log('bun-setup.ts loaded - document:', typeof (global as any).document);
|
|
console.log('document.body:', (global as any).document?.body);
|
|
|
|
// Import jest-dom matchers after setting up the DOM
|
|
import '@testing-library/jest-dom';
|
|
|
|
// Clear document body after each test
|
|
import { afterEach } from 'bun:test';
|
|
afterEach(() => {
|
|
if (global.document?.body) {
|
|
global.document.body.innerHTML = '';
|
|
}
|
|
});
|