Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #187 #188

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var MqttClient = module.exports =
function MqttClient(streamBuilder, options) {
var that = this;

if (!this instanceof MqttClient) {
return new MqttClient(stream, options);
if (!(this instanceof MqttClient)) {
return new MqttClient(streamBuilder, options);
}

this.options = options || {};
Expand Down
3 changes: 2 additions & 1 deletion test/abstract_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Testing dependencies
*/
var should = require('should');
var should = require('should')
, MqttClient = require('../lib/client');

module.exports = function(server, createClient, port) {
describe('closing', function() {
Expand Down
23 changes: 21 additions & 2 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var mqtt = require('..')
, should = require('should')
, abstractClientTests = require("./abstract_client");

/**
Expand Down Expand Up @@ -73,10 +74,28 @@ var server = mqtt.createServer(function (client) {


describe('MqttClient', function() {
describe('creating', function() {
it('should allow instantiation of MqttClient without the \'new\' operator' , function(done) {
should(function() {
var client;

try {
client = mqtt.MqttClient(function() {
throw Error('break');
}, {});
} catch (err) {
if (err.message !== 'break') {
throw err;
}
done();
}
}).not.throw("Object #<Object> has no method '_setupStream'");
});
});

abstractClientTests(server, createClient, port);

describe('message ids', function() {

it('should increment the message id', function() {
var client = createClient();
var currentId = client._nextId();
Expand Down