Skip to content

Commit

Permalink
adding more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
yawetse committed Mar 27, 2017
1 parent db4358d commit 33a432e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function connect(dbpath = defaultDBPath, options = {}, lowkieConfig = {}) {
const db = new loki(dbname, lokiDBOptions);
const ensureAdapterFilePromise = () => {
if (!this.config.adapterType) {
throw new Error('Invalid Adapter Type');
return Promise.reject(new Error('Invalid Adapter Type'));
} else {
return (this.config.adapterType === 'file')
? new Promise((resolve, reject) => {
Expand Down Expand Up @@ -76,6 +76,7 @@ function connect(dbpath = defaultDBPath, options = {}, lowkieConfig = {}) {
});
})
.catch((e) => {
this.connection.emit('connectionError', e, { dbname, options, });
reject(e);
});
});
Expand Down
27 changes: 27 additions & 0 deletions test/unit/connect_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,33 @@ describe('Connect', function () {
done();
});
});
it('should throw error on invalid adapter types and emit error', (done) => {
let newLOWKIE = new lowkieClass({});
let lowkieConnect = lowkieConnectTest.bind(newLOWKIE);
let throwawayfilepath = invalidFILEPATH;
// expect(lowkieConnect.bind(lowkieConnect, throwawayfilepath, {}, {
// overwriteInvalidJSON: false,
// adapterType: false,
// })).to.throw(Error);
lowkieConnect(throwawayfilepath, {}, {
overwriteInvalidJSON: false,
adapterType:false,
})
.then(() => {
// console.log('resoved here')
// console.log('newLOWKIE.config', newLOWKIE.config);
// done();
})
.catch(e => {
expect(e).to.be.instanceof(Error);
// done();
});

newLOWKIE.connection.once('connectionError', (e) => {
expect(e).to.be.instanceOf(Error);
done();
});
});
// it('should emit connection error', (done) => {
// let newLOWKIE = new lowkieClass({});
// let lowkieConnect = lowkieConnectTest.bind(newLOWKIE);
Expand Down

0 comments on commit 33a432e

Please sign in to comment.