Skip to content

Commit

Permalink
fix(test): prevent OverwriteModelError with mocha watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kristian Flaatten committed Aug 25, 2016
1 parent e0fd5ed commit 585e749
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion models/Checkin.js
Expand Up @@ -20,4 +20,9 @@ const checkinSchema = new Schema({

checkinSchema.index({ location: '2dsphere' });

module.exports = mongoose.model('Checkin', checkinSchema);
// Fix for https://github.com/Automattic/mongoose/issues/1251
try {
module.exports = mongoose.model('Checkin');
} catch (_) {
module.exports = mongoose.model('Checkin', checkinSchema);
}
7 changes: 6 additions & 1 deletion models/User.js
Expand Up @@ -12,4 +12,9 @@ const userSchema = new Schema({
innsjekkinger: [{ type: Schema.Types.ObjectId, ref: 'Checkin' }],
});

module.exports = mongoose.model('User', userSchema);
// Fix for https://github.com/Automattic/mongoose/issues/1251
try {
module.exports = mongoose.model('User');
} catch (_) {
module.exports = mongoose.model('User', userSchema);
}
4 changes: 0 additions & 4 deletions test/index.js
@@ -1,6 +1,5 @@
'use strict';

const mongoose = require('mongoose');
const mongo = require('../lib/db');

const User = require('../models/User');
Expand All @@ -13,9 +12,6 @@ const checkins = require('./fixtures/checkins');
before(function before(done) {
this.timeout(10000);

mongoose.models = {};
mongoose.modelSchemas = {};

if (mongo.connection._hasOpened) {
process.nextTick(done);
} else {
Expand Down

0 comments on commit 585e749

Please sign in to comment.