[FIX] fix connection error handling

if connection to server can't be established, reject Promise of `connect()` method caller,
instead of throwing error event on base object.
This commit is contained in:
Ivan Tivonenko
2016-02-24 06:09:19 +02:00
parent 7c9a179865
commit 4acc42e1b6
2 changed files with 38 additions and 2 deletions

View File

@@ -106,6 +106,26 @@ describe('Connection', function() {
});
});
it('should throw NotConnectedError if server not responding ', function(
done
) {
if (process.browser) {
const phantomTest = /PhantomJS/;
if (phantomTest.test(navigator.userAgent)) {
// inside PhantomJS this one just hangs, so skip as not very relevant
done();
return;
}
}
const connection = new utils.common.Connection('ws://127.0.0.1:321');
connection.on('error', done);
connection.connect().catch(error => {
assert(error instanceof this.api.errors.NotConnectedError);
done();
});
});
it('DisconnectedError', function() {
this.api.connection._send(JSON.stringify({
command: 'config',