From 51870a7b607be13d5e8b3824d166368d140f9f9a Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Wed, 17 Jul 2013 01:35:16 +0200 Subject: [PATCH] getCandidates is tested in the browser --- browser-version/test/nedb-browser.js | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/browser-version/test/nedb-browser.js b/browser-version/test/nedb-browser.js index 53f5306..d8ffff7 100644 --- a/browser-version/test/nedb-browser.js +++ b/browser-version/test/nedb-browser.js @@ -242,4 +242,37 @@ describe('Basic CRUD functionality', function () { }); }); -}); +}); // ==== End of 'Basic CRUD functionality' ==== // + + +describe('Indexing', function () { + + it('getCandidates works as expected', function (done) { + var db = new Nedb(); + + db.insert({ a: 4 }, function () { + db.insert({ a: 6 }, function () { + db.insert({ a: 7 }, function () { + var candidates = db.getCandidates({ a: 6 }) + candidates.length.should.equal(3); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 4; })); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 7; })); + + db.ensureIndex({ fieldName: 'a' }); + + candidates = db.getCandidates({ a: 6 }) + candidates.length.should.equal(1); + assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); + + done(); + }); + }); + }); + }); + + +}); // ==== End of 'Indexing' ==== // + + +