mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 23:43:19 +08:00
32 lines
661 B
JavaScript
32 lines
661 B
JavaScript
const mongoose = require('../../mongoose');
|
|
|
|
// Ensure the NODE_ENV is set to 'test',
|
|
// this is helpful when you would like to change behavior when testing.
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
beforeEach(function (done) {
|
|
function clearDB() {
|
|
for (let i in mongoose.connection.collections) {
|
|
mongoose.connection.collections[i].remove(function() {});
|
|
}
|
|
return done();
|
|
}
|
|
|
|
if (mongoose.connection.readyState === 0) {
|
|
mongoose.on('open', function() {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
return clearDB();
|
|
});
|
|
} else {
|
|
return clearDB();
|
|
}
|
|
});
|
|
|
|
after(function (done) {
|
|
mongoose.disconnect();
|
|
return done();
|
|
});
|