Skip to content

Instantly share code, notes, and snippets.

@nkzawa nkzawa/.travis.yml
Last active Feb 16, 2018

Embed
What would you like to do?
Testing mongoose models with mocha
language: node_js
node_js:
- 0.8
services:
- mongodb
mongoose = require 'mongoose'
mongoose.connect 'mongodb://localhost/test'
connection = mongoose.connection
before (done) ->
connection.on 'open', ->
connection.db.dropDatabase done
after (done) ->
connection.close done
module.exports = ->
afterEach (done) ->
connection.db.dropDatabase done
{
"name": "testing-mongoose-models-with-mocha",
"version": "1.0.0",
"scripts": {
"test": "PATH=./node_modules/.bin:$PATH; mocha --compilers coffee:coffee-script src"
},
"dependencies": {
"coffee-script": "1.4.0",
"mongoose": "3.5.6"
},
"devDependencies": {
"mocha": "1.8.1",
"chai": "1.5.0"
}
}
{expect} = require 'chai'
db = require './db'
User = require './user'
describe 'User', ->
# call when testing db
db()
describe '#save', ->
it 'should save user', (done) ->
data = {email: 'foo@example.com'}
user = new User data
user.save (err, user) ->
done err if err
expect(user.email).to.equal data.email
expect(user.created).to.exist
done()
mongoose = require 'mongoose'
schema = new mongoose.Schema
email: String
created: {type: Date, default: Date.now}
module.exports = mongoose.model 'User', schema
@brianconnoly

This comment has been minimized.

Copy link

commented Feb 16, 2018

Is it unfinished?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.