0
votes

While establishing the connection using socket

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done( )" is called; if returning a Promise, ensure it resolves.

Given below is the code reference of the same

beforeEach(function(done) {    
    var socketOptions = {};
    var socket = io.connect("http://localhost:5000", socketOptions);
    socket.on('connect', function () {
         console.log('Connection Established');
         setTimeout(done, 500);
    });
    socket.on('error', function (err) {
        console.log('Connection Error', err);
        setTimeout(done, 500);
    });
});

While checking the error of socket connection, I'm getting the error mentioned below:

Connection Error { Error: xhr poll error
at XHR.Transport.onError (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transport.js:64:13)
at Request.<anonymous> (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transports\polling-xhr.js:129:10)
at Request.Emitter.emit (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\node_modules\component-emitter\index.js:133:20)
at Request.onError (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transports\polling-xhr.js:307:8)
at Timeout._onTimeout (F:\Projects\SDK\dynamicLocationServer\node_modules\engine.io-client\lib\transports\polling-xhr.js:254:18)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5) type: 'TransportError', description:400}
1
done is not defined you might need to specify it as argument beforeEach(function(done)Yury Tarabanko
I've specified it, but still getting the same error. If I call the done outside the socket connect, then it will work. Even if the connection fails, the test case will be resulting as passed.Subba
Are you sure this line logs console.log('Connection Established');?Yury Tarabanko
No, it is not getting logged even if server is up and runningSubba
Issue is resolved by changing the socketOptions variable data like var socketOptions = {'transports': ['websocket']};. Thanks for the help @YuryTarabankoSubba

1 Answers

1
votes

Issue is resolved by changing the socketOptions variable data like

var socketOptions = {'transports': ['websocket']};

Since the error is on transport error polling, we need to specify the way of transports as options as pass with the socket connection options