Skip to content

Instantly share code, notes, and snippets.

@pghalliday
Created July 18, 2012 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pghalliday/3135534 to your computer and use it in GitHub Desktop.
Save pghalliday/3135534 to your computer and use it in GitHub Desktop.
var mongoose = require('./testUtils/mongooseTestWrapper.js'),
Greetee;
exports.setUp = function(callback) {
// reset the schemas to ensure that any changes are picked up by the mongoose singleton
mongoose.resetSchemas();
// add the schemas back again
Greetee = require('./greetee.js');
// connect to a test database and drop all the greetees from it
mongoose.connect('mongodb://localhost/UnitTest_Greetee');
Greetee.remove({}, function(err) {
callback();
});
};
...
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var GreeteeSchema = new Schema({
name: String
});
GreeteeSchema.methods.greeting = function() {
return 'Hello, ' + this.name;
};
module.exports = mongoose.model('Greetee', GreeteeSchema);
var mongoose = require('mongoose'),
Greetee = require('./greetee.js');
exports.setUp = function(callback) {
// connect to a test database and drop all the greetees from it
mongoose.connect('mongodb://localhost/UnitTest_Greetee');
Greetee.remove({}, function(err) {
callback();
});
};
exports.tearDown = function(callback) {
mongoose.disconnect();
callback();
};
exports.greeting = function(test) {
test.expect(1);
var greetee = new Greetee({
name: 'Pete'
});
test.equal('Hello, Pete', greetee.greeting());
test.done();
};
var mongoose = require('mongoose');
mongoose.resetSchemas = function() {
this.modelSchemas = {};
this.models = {};
};
module.exports = mongoose;
...
GreeteeSchema.methods.greeting = function() {
return 'Bonjour, ' + this.name;
};
...
...
exports.greeting = function(test) {
test.expect(1);
var greetee = new Greetee({
name: 'Pete'
});
test.equal('Bonjour, Pete', greetee.greeting());
test.done();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment