diff --git a/lib/client.js b/lib/client.js index 0d023db7c..feedebbd8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -352,7 +352,10 @@ Client.prototype.query = function (config, values, callback) { // can take in strings, config object or query object var query var result - if (typeof config.submit === 'function') { + + if (config === null || config === undefined) { + throw new TypeError('Client was passed a null or undefined query') + } else if (typeof config.submit === 'function') { result = query = config if (typeof values === 'function') { query.callback = query.callback || values diff --git a/test/unit/client/simple-query-tests.js b/test/unit/client/simple-query-tests.js index 363c44dbe..3d1deef41 100644 --- a/test/unit/client/simple-query-tests.js +++ b/test/unit/client/simple-query-tests.js @@ -120,4 +120,24 @@ test('executing query', function () { }) }) }) + + test('handles errors', function () { + var client = helper.client() + + test('throws an error when config is null', function () { + try { + client.query(null, undefined) + } catch (error) { + assert.equal(error.message, 'Client was passed a null or undefined query', 'Should have thrown an Error for null queries') + } + }) + + test('throws an error when config is undefined', function () { + try { + client.query() + } catch (error) { + assert.equal(error.message, 'Client was passed a null or undefined query', 'Should have thrown an Error for null queries') + } + }) + }) })