本文整理匯總了TypeScript中mock-socket.Server.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Server.on方法的具體用法?TypeScript Server.on怎麽用?TypeScript Server.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mock-socket.Server
的用法示例。
在下文中一共展示了Server.on方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should send a request', done => {
const brayns = new Client(host);
mockServer.on('connection', socket => {
// TODO: (socket as any) is due to https://github.com/thoov/mock-socket/issues/224,
// remove when fixed
(socket as any).on('message', (data: any) => {
const json = fromJson<JsonRpcRequest>(data);
expect(isJsonRpcRequest(json)).toBe(true);
expect(json.id).toBeDefined();
expect(json.method).toBe(INSPECT);
expect(json.params).toEqual({
ping: true
});
const response = toResponseJson(json, true);
socket.send(response);
});
});
brayns.request(INSPECT, {ping: true} as any)
.then(() => {
done();
});
});
示例2: it
it('should connect', (done) => {
mockwebSocketServer.on('connection', () => {
done();
});
dotEventsSocket.connect().subscribe(() => {});
});
示例3: before
before(function () {
const fakeURL = 'ws://localhost:8080/peerjs?key=peerjs&id=1&token=testToken';
mockServer = new Server(fakeURL);
mockServer.on('connection', socket => {
//@ts-ignore
socket.on('message', data => {
socket.send('test message from mock server');
});
socket.send(ServerMessageType.Open);
});
});