2

I installed socket.io in my node js and established a connection and emitting events from NodeJs and it is working fine. Check the below code that I have written.

const io = require('socket.io')(server, {
cors: {
    origin: "http://localhost:4200",
    methods: ["GET", "POST"]
}
});
io.on('connection', (socket)=>{
console.log('Client connected');
io.emit('message', items);
socket.on('message', data => {
    console.log('this is server data', data);
    items.push(data);
    io.emit('message', items);
})

Now everything is working fine from front end and backend as well except for unit test cases.

I'm not able to cover the connection part of the socket.io in NodeJS.

I'm using Jest to do that. I used the example provided in the below link :

https://socket.io/docs/v4/testing/#example-with-jest

It is not throwing any error but the code for socket connection is not getting covered at all. Screen shot of code coverage

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.