Skip to content

Instantly share code, notes, and snippets.

@aherve
Last active December 7, 2016 13:28
Show Gist options
  • Select an option

  • Save aherve/d03c82aa677036e77559fe4c6891ce1f to your computer and use it in GitHub Desktop.

Select an option

Save aherve/d03c82aa677036e77559fe4c6891ce1f to your computer and use it in GitHub Desktop.
import { expect } from 'chai'
describe('Stuff', () => {
// -------THE CALLBACK WAY------- //
it('looks ugly with callbacks', (done) => {
User.count({}, (err, count) => {
if (err) { return done(err) }
expect(count).to.be.above(1)
User.findOne({}, (err, user) => {
if (err) { return done(err) }
expect(user).to.have.property('email')
done()
})
})
})
// ------- BETTER WITH PROMISES ------- //
it('looks ok with promises', () => {
return User.count({}).then(count => {
expect(count).to.be.above(1)
user.findOne({}).then(user => {
expect(user).to.have.property('email')
})
})
})
// ------- AWAIT IS AWESOME ------- //
it('looks great with await !', async () => {
expect(await User.count({})).to.be.above(1)
expect(await User.findOne({})).to.have.property('email')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment