From 42680c0ca0d742a225fb37912c5544b2f2c3b079 Mon Sep 17 00:00:00 2001 From: Chuanyu Wang Date: Mon, 16 Nov 2020 20:12:43 +0800 Subject: [PATCH] Add unit test for connection options --- test/database.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/database.js b/test/database.js index 4ba463b..19ebf05 100644 --- a/test/database.js +++ b/test/database.js @@ -59,6 +59,23 @@ describe('database', function() { await dbShort.close(); }); + it('should accept connection with options', async () => { + // auth should fail with invalid 'authSource', to make sure options take effect + const cannotConnect = mongoist('localhost:27017/test', { 'authSource': 'dummy' }); + let errorEvent = null; + cannotConnect.on('error', (error) => { + errorEvent = error; + }); + + try { + await cannotConnect.test.find(); + await cannotConnect.close(); + } catch (e) { + expect(errorEvent).to.exist; + return; + } + }); + it('should create a collection', async() => { const collection = await db.createCollection('test123');