forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgateway-ack.spec.ts
32 lines (27 loc) · 901 Bytes
/
gateway-ack.spec.ts
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
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as io from 'socket.io-client';
import { AckGateway } from '../src/ack.gateway';
async function createNestApp(...gateways): Promise<INestApplication> {
const testingModule = await Test.createTestingModule({
providers: gateways,
}).compile();
const app = await testingModule.createNestApplication();
return app;
}
describe('WebSocketGateway (ack)', () => {
let ws, app;
it(`should handle message with ack (http)`, async () => {
app = await createNestApp(AckGateway);
await app.listenAsync(3000);
ws = io.connect('http://localhost:8080');
await new Promise(resolve =>
ws.emit('push', { test: 'test' }, data => {
expect(data).to.be.eql('pong');
resolve();
}),
);
});
afterEach(() => app.close());
});