-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjest.setup.ts
More file actions
26 lines (20 loc) · 1.02 KB
/
jest.setup.ts
File metadata and controls
26 lines (20 loc) · 1.02 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
import { TextDecoder, TextEncoder } from 'util';
global.TextDecoder = TextDecoder as any;
global.TextEncoder = TextEncoder as any;
const mockDataChannel = { onopen: null, onmessage: null, send: jest.fn(), readyState: 'open' };
const mockPeerConnection = {
createDataChannel: jest.fn(() => mockDataChannel),
onicecandidate: jest.fn(),
oniceconnectionstatechange: jest.fn(),
ontrack: jest.fn(),
setRemoteDescription: jest.fn().mockResolvedValue(undefined),
createAnswer: jest.fn().mockResolvedValue({ type: 'answer', sdp: 'mock-sdp' }),
setLocalDescription: jest.fn().mockResolvedValue(undefined),
close: jest.fn(),
iceConnectionState: 'connected',
};
const mockRTCPeerConnection = jest.fn().mockImplementation(() => mockPeerConnection);
(mockRTCPeerConnection as any).generateCertificate = jest.fn().mockResolvedValue({});
// Mock MediaStream
global.MediaStream = jest.fn().mockImplementation(() => ({ getTracks: jest.fn(() => []) }));
global.window.RTCPeerConnection = mockRTCPeerConnection as any;