Skip to content

Instantly share code, notes, and snippets.

@JoeShep
Created March 14, 2017 20:42
Show Gist options
  • Save JoeShep/a727ed069d36ad6bde08c4c984761ac3 to your computer and use it in GitHub Desktop.
Save JoeShep/a727ed069d36ad6bde08c4c984761ac3 to your computer and use it in GitHub Desktop.
Mocha: Testing with Promises
'use strict';
const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('./acme.sqlite', (wat) => {
console.log("Is this connection open?", wat);
});
const getCustomer = (custPhone) => {
return new Promise( (resolve, reject) => {
db.get(`SELECT first_name, last_name FROM customers WHERE phone = "${custPhone}"`, (err, customer) => {
console.log("customer?", customer);
let customerName = `${customer.first_name} ${customer.last_name}`;
console.log("customer name", customerName);
resolve(customerName);
});
});
}
module.exports = { getCustomer }
const { assert: {equal} } = require('chai');
const { getCustomer } = require('./main');
describe('main', () => {
describe('getCustomer', () => {
it('should return a customer', () => {
return getCustomer('615-555-5309')
.then( (customer) => {
console.log("customer in then", customer);
equal("Danny Elfman", customer)
});
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment