本文整理汇总了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);
});
});