-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
34 lines (28 loc) · 937 Bytes
/
jest.setup.ts
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
// jest.setup.ts
import '@testing-library/jest-dom';
import { server } from './src/mocks/server';
// Establish API mocking before all tests
beforeAll(() => server.listen());
// Reset any request handlers that we may add during the tests
afterEach(() => {
server.resetHandlers();
jest.clearAllMocks();
});
// Clean up after the tests are finished
afterAll(() => server.close());
// Mock WebSocket
global.WebSocket = class MockWebSocket {
onopen: () => void = () => {};
onclose: () => void = () => {};
onmessage: (data: any) => void = () => {};
onerror: () => void = () => {};
send: jest.Mock = jest.fn();
close: jest.Mock = jest.fn();
constructor(url: string) {
setTimeout(() => this.onopen(), 0);
}
};
// Mock environment variables
process.env.JWT_SECRET = 'test-secret';
process.env.PLEX_CLIENT_IDENTIFIER = 'test-client-id';
process.env.DATABASE_URL = 'postgresql://test:test@localhost:5432/votarr_test';