diff --git a/index.js b/index.js index f126306e..6f622bac 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,9 @@ var EventEmitter = require('events').EventEmitter var objectAssign = require('object-assign') var Pool = module.exports = function (options, Client) { + if (!(this instanceof Pool)) { + return new Pool(options, Client) + } EventEmitter.call(this) this.options = objectAssign({}, options) this.log = this.options.log || function () { } diff --git a/test/index.js b/test/index.js index a7103af6..e4616a43 100644 --- a/test/index.js +++ b/test/index.js @@ -12,6 +12,12 @@ if (typeof global.Promise === 'undefined') { } describe('pool', function () { + it('can be used as a factory function', function () { + var pool = Pool() + expect(pool instanceof Pool).to.be.ok() + expect(typeof pool.connect).to.be('function') + }) + describe('with callbacks', function () { it('works totally unconfigured', function (done) { var pool = new Pool()