시리즈: next.js
typescript
61 줄
· 업데이트 2026-02-03
setup.ts
next.js/backend/src/__tests__/setup.ts
// Test setup file for Jest
// Configures the testing environment and global test utilities
import { PrismaClient } from '@prisma/client';
// Mock Prisma client for testing
jest.mock('@prisma/client', () => ({
PrismaClient: jest.fn().mockImplementation(() => ({
response: {
create: jest.fn(),
findUnique: jest.fn(),
findMany: jest.fn(),
count: jest.fn(),
delete: jest.fn(),
},
$disconnect: jest.fn(),
})),
}));
// Global test timeout
jest.setTimeout(10000);
// Clean up after each test
afterEach(() => {
jest.clearAllMocks();
});
// Global test utilities
global.testUtils = {
// Helper to create mock response data
createMockResponse: (overrides = {}) => ({
id: 'test-id-123',
answers: {
q1: 'A',
q2: ['X', 'Y'],
q3: 'Test comment'
},
userAgent: 'Test User Agent',
ipHash: 'test-hash',
createdAt: new Date('2025-01-23T10:00:00Z'),
...overrides
}),
// Helper to create mock request data
createMockRequest: (overrides = {}) => ({
answers: {
q1: 'A',
q2: ['X', 'Y'],
q3: 'Test comment'
},
...overrides
})
};
// Type declarations for global test utilities
declare global {
var testUtils: {
createMockResponse: (overrides?: any) => any;
createMockRequest: (overrides?: any) => any;
};
}
관련 글
next.js
javascript
업데이트 2026-02-03
jest.config.js
jest.config.js — javascript source code from the next.js learning materials (next.js/backend/jest.config.js).
글 읽기 →
next.js
typescript
업데이트 2026-02-03
index.ts
index.ts — typescript source code from the next.js learning materials (next.js/backend/src/index.ts).
글 읽기 →
next.js
typescript
업데이트 2026-02-03
responses.ts
responses.ts — typescript source code from the next.js learning materials (next.js/backend/src/routes/responses.ts).
글 읽기 →
next.js
typescript
업데이트 2026-02-03
validation.ts
validation.ts — typescript source code from the next.js learning materials (next.js/backend/src/schemas/validation.ts).
글 읽기 →
next.js
typescript
업데이트 2026-02-03
seed.ts
seed.ts — typescript source code from the next.js learning materials (next.js/backend/src/scripts/seed.ts).
글 읽기 →
next.js
typescript
업데이트 2026-02-03
prisma.ts
prisma.ts — typescript source code from the next.js learning materials (next.js/backend/src/services/prisma.ts).
글 읽기 →