Last active
December 7, 2016 13:28
-
-
Save aherve/d03c82aa677036e77559fe4c6891ce1f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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