Skip to content

Commit fc07c4b

Browse files
committed
Unit testing (jest)
1 parent 63af931 commit fc07c4b

File tree

4 files changed

+7913
-3463
lines changed

4 files changed

+7913
-3463
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ dist
105105

106106
# Database
107107
*.db
108+
109+
# Jest
110+
*.test.js

lib/queries.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ function close() {
2424
/**
2525
* Dynamically opens and closes a database if a file is provided.
2626
* @param {string} file
27-
* @returns {Promise<Function>}
27+
* @returns {void|Promise<Function>}
2828
*/
2929
function dynamicAccess(file) {
3030
// If file is undefined or db is already open, do nothing
31-
if (!file || db) {
31+
if (!file || db instanceof PromiseDB) {
3232
return;
3333
}
3434

@@ -47,8 +47,13 @@ module.exports = {
4747
// Export database open/close functions (synchronous!)
4848
open, close,
4949

50-
print: function() {
51-
console.log(typeof db);
50+
/**
51+
* Retrieves the database, if open.
52+
* @returns {PromiseDB}
53+
*/
54+
getDatabase: function() {
55+
if (db instanceof PromiseDB) return db;
56+
throw new Error('Database is not open.');
5257
},
5358

5459
/**

0 commit comments

Comments
 (0)