diff --git a/lib/datasource.js b/lib/datasource.js index 5e7bf66b..e5826ed8 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1225,7 +1225,7 @@ DataSource.prototype.discoverSchema = function (modelName, options, cb) { cb = cb || utils.createPromiseCallback(); this.discoverSchemas(modelName, options, function (err, schemas) { - if (err) { + if (err || !schemas) { cb && cb(err, schemas); return; } @@ -1305,7 +1305,7 @@ DataSource.prototype.discoverSchemas = function (modelName, options, cb) { var columns = results[0]; if (!columns || columns.length === 0) { - cb(); + cb(new Error('Table \''+modelName+'\' does not exist.')); return cb.promise; } diff --git a/test/discovery.test.js b/test/discovery.test.js index 26e5056c..3bd9e3df 100644 --- a/test/discovery.test.js +++ b/test/discovery.test.js @@ -602,3 +602,27 @@ describe('discoverExportedForeignKeys', function(){ }); }); }); + +describe('Default memory connector', function() { + var ds, nonExistantError = 'Table \'NONEXISTENT\' does not exist.'; + + before(function() { + ds = new DataSource({connector: 'memory'}); + }); + + it('discoverSchema should return an error when table does not exist', function(done) { + ds.discoverSchema('NONEXISTENT', {}, function(err, schemas) { + should.exist(err); + err.message.should.eql(nonExistantError); + done(); + }); + }); + + it('discoverSchemas should return an error when table does not exist', function(done) { + ds.discoverSchemas('NONEXISTENT', {}, function(err, schemas) { + should.exist(err); + err.message.should.eql(nonExistantError); + done(); + }); + }); +});