Skip to content

Commit 2a3c56b

Browse files
committed
Unit test
1 parent 546cf0d commit 2a3c56b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { BaseEndpointTypes } from '../../src/endpoint/stock-quotes'
2+
import { buildWsTransport } from '../../src/transport/ws'
3+
4+
describe('DxFeed WebSocket Transport', () => {
5+
let mockConnection: { send: jest.Mock }
6+
let transport: ReturnType<typeof buildWsTransport<BaseEndpointTypes>>
7+
8+
beforeEach(() => {
9+
mockConnection = { send: jest.fn() }
10+
11+
transport = buildWsTransport<BaseEndpointTypes>(
12+
(params) => [{ Quote: [params.base.toUpperCase()] }],
13+
() => [],
14+
)
15+
})
16+
17+
afterEach(() => {
18+
jest.clearAllMocks()
19+
})
20+
21+
describe('heartbeat handler', () => {
22+
it('should send heartbeat message when called', () => {
23+
;(transport as any).connectionClientId = 'test-client-id'
24+
;(transport as any).config.handlers.heartbeat(mockConnection)
25+
26+
expect(mockConnection.send).toHaveBeenCalledTimes(1)
27+
28+
const sentMessage = mockConnection.send.mock.calls[0][0]
29+
expect(sentMessage).toEqual(
30+
'[{"id":1,"clientId":"test-client-id","channel":"/meta/connect","connectionType":"websocket"}]',
31+
)
32+
})
33+
})
34+
})

0 commit comments

Comments
 (0)