Created
April 13, 2013 08:44
-
-
Save jkresner/5377631 to your computer and use it in GitHub Desktop.
TDD nodejs, mocha, mongo, mongoose with a test database
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
mongoose = require 'mongoose' | |
wipeDbAfterTests = true | |
describe "Your test suite", -> | |
# connect to our mongo test database, note how done is passed to mongoose connect | |
before (done) -> | |
mongoose.connect "mongodb://localhost/airpair_test", done | |
# your test | |
it "your test", (done) -> | |
# some call that has mongoose in there somewhere, you'll | |
# need to call done at some point as mongoose is async | |
done() | |
# close our mongoose connection, other wise your next test suite will fail | |
# saying there is already an open connection | |
after (done) -> | |
if ! wipeDbAfterTests | |
mongoose.connection.close done | |
else | |
mongoose.connection.db.executeDbCommand { dropDatabase:1 }, (err, result) -> | |
mongoose.connection.close done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment