This repository was archived by the owner on Jul 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjest.setup.js
More file actions
62 lines (56 loc) · 1.79 KB
/
Copy pathjest.setup.js
File metadata and controls
62 lines (56 loc) · 1.79 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
import { WebSocket } from "ws"
import { mockWebSocket } from "./tests/helpers/mock-websocket"
// Mock @obsidion/bridge module
jest.mock("@obsidion/bridge", () => {
// Create a mock public key
const mockPublicKey = new Uint8Array(32)
for (let i = 0; i < mockPublicKey.length; i++) {
mockPublicKey[i] = i
}
const mockBridgeInstance = {
connect: jest.fn(),
onMessage: jest.fn(),
send: jest.fn(),
close: jest.fn(),
isConnected: jest.fn().mockReturnValue(true),
getWebSocketClient: mockWebSocket().getWebSocketClient,
getPublicKey: jest.fn().mockReturnValue(mockPublicKey),
onConnect: jest.fn().mockImplementation((callback) => {
callback(false)
return () => {}
}),
onSecureChannelEstablished: jest.fn().mockImplementation((callback) => {
callback()
return () => {}
}),
onSecureMessage: jest.fn().mockImplementation((callback) => {
return () => {}
}),
connection: {
connectionString: "wss://bridge.zkpassport.localhost",
getBridgeId: jest.fn().mockReturnValue("test-topic-123"),
isConnected: jest.fn().mockReturnValue(true),
keyPair: {
publicKey: mockPublicKey,
privateKey: new Uint8Array(32),
},
},
}
const MockBridge = jest.fn().mockImplementation(() => mockBridgeInstance)
// Add static create method
MockBridge.create = jest.fn().mockImplementation(async ({ keyPair, bridgeId } = {}) => {
if (keyPair) {
mockBridgeInstance.connection.keyPair = keyPair
}
if (bridgeId) {
mockBridgeInstance.connection.getBridgeId = jest.fn().mockReturnValue(bridgeId)
}
return mockBridgeInstance
})
return {
Bridge: MockBridge,
BridgeInterface: jest.fn(),
}
})
// Fallback for environments without WebSocket
global.WebSocket = WebSocket