diff --git a/test/db.test.js b/test/db.test.js index 354f085..8414fa8 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -145,6 +145,37 @@ describe('Database', function () { ], done); }); + it('Can find one document matching a basic query and return null if none is found', function (done) { + var d = new Datastore(testDb); + + async.waterfall([ + function (cb) { + d.loadDatabase(function (err) { + d.insert({ somedata: 'ok' }, function (err) { + d.insert({ somedata: 'again', plus: 'additional data' }, function (err) { + d.insert({ somedata: 'again' }, function (err) { return cb(err); }); + }); + }); + }); + } + , function (cb) { // Test with query that will return docs + d.findOne({ somedata: 'ok' }, function (err, doc) { + assert.isNull(err); + Object.keys(doc).length.should.equal(2); + doc.somedata.should.equal('ok'); + assert.isDefined(doc._id); + return cb(); + }); + } + , function (cb) { // Test with query that doesn't match anything + d.findOne({ somedata: 'nope' }, function (err, doc) { + assert.isNull(err); + assert.isNull(doc); + return cb(); + }); + } + ], done); + }); }); // ==== End of 'Find' ==== //