Skip to content

Commit

Permalink
Add reconnect method and test.
Browse files Browse the repository at this point in the history
Add reconnect method.
Add new test using reconnect method.
  • Loading branch information
Kwon Hyungjoo committed Feb 3, 2020
1 parent dbc0573 commit 685ac95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class AsyncClient {
})
}

reconnect (...args) {
return this._client.reconnect(...args);
}

addListener (...args) {
return this._client.addListener(...args);
}
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ function runTests () {
return client.end();
});
});

test('Calling reconnect after end should resolve once reconnect', t => {
t.plan(2);

const client = AsyncMQTT.connect(SERVER_URL);

client.once('reconnect', () => {
t.pass('Reconnect event occured');
client.once('connect', () => {
client.end();
});
});

client.once('connect', () => {
client.end().then(() => {
t.pass('End resolved');
client.reconnect();
});
});
});
}

// Taken from MQTT.js tests
Expand Down

0 comments on commit 685ac95

Please sign in to comment.