Comments (8)
Based on nestjs/nest#1368, I was able to connect to the io server in my e2e tests with the following code. It allows testing a WebSocket implementation with the socket.io-client.
const address = app.getHttpServer().listen().address();
const baseAddress = `http://[${address.address}]:${address.port}`;
const client = io.connect(`${baseAddress}/some-namespace`);
from docs.nestjs.com.
Any news about socket unit testing ???
Still can't find a proper solution 🤷♂️
from docs.nestjs.com.
Any progress? With gateway example provided, I added EventsGateway in my e2e or controller test provider and when I emit a message from my service, it says websocket server is null
from docs.nestjs.com.
Solution of @ifl0w works perfectly. Here's my test case:
import * as WebSocket from 'ws'
beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [
SocketModule,
],
})
.compile()
app = moduleFixture.createNestApplication()
app.useWebSocketAdapter(new WsAdapter(app))
await app.init()
})
it('should connect successfully', (done) => {
const address = app.getHttpServer().listen().address()
const baseAddress = `http://[${address.address}]:${address.port}`
const socket = new WebSocket(baseAddress)
socket.on('open', () => {
console.log('I am connected! YEAAAP')
done()
})
socket.on('close', (code, reason) => {
done({ code, reason })
})
socket.on ('error', (error) => {
done(error)
})
})
But I observe there's a problem if I have more than 1 test case inside same describe
block, it won't work, I try debug using beforeAll, beforeEach, afterAll, afterEach
and it doesn't help. Then I need to separate each test case to be run inside 1 separate describe
block
from docs.nestjs.com.
Anybody knows how to test SSE? I'm getting req.socket.setKeepAlive is not a function
from docs.nestjs.com.
I'm having similar issues. In my test I do can connect to the server but the socket.id on server and client sides is undefined, therefore I can't emit any message from the client or the server.
from docs.nestjs.com.
Any updates on this?
from docs.nestjs.com.
An example of how to unit test guards would be nice, in particular the canActivate
method which requires an ExecutionContext
.
from docs.nestjs.com.
Related Issues (20)
- Navigating to articles for previous versions redirects the user to the home page. HOT 1
- Suggestion for Document Function Display HOT 2
- Enhanced AI Access for NestJS Documentation HOT 1
- Update Queues docs guide to use bullmq instead of bull package HOT 2
- Difficulty in navigating topics on a page HOT 1
- Add docs on typescript-only features of `nest generate` commmand HOT 1
- WebSocketServer decorator gives unexpected value HOT 1
- Document the `type` and `disposition` options of `StreamableFile`
- Ads cover content HOT 2
- Better docs for implicit request scoped providers HOT 7
- [Docs] Small update to CLI Plugin page for clarity HOT 1
- How can I send header with kafka clientKafka=>send HOT 2
- [Docs] missing link in 'Devtools - CI/CD integration' HOT 1
- how to correctly do versioning with express adapter? HOT 2
- Unknown authentication strategy "jwt" HOT 1
- Dynamic modules exports confusion HOT 1
- [Authentication] Docs should address how to handle logging out, as well as logging in
- Issues and PR Summary HOT 1
- Documentation Issue: Missing explanation for statement HOT 2
- Documentation Issue/Discussion: Business logic in the exception filter? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.nestjs.com.