Created
March 14, 2017 20:42
-
-
Save JoeShep/a727ed069d36ad6bde08c4c984761ac3 to your computer and use it in GitHub Desktop.
Mocha: Testing with Promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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