egg-mongoose-mock
v3.3.14
Published
egg mongoose using mock server plugin
Downloads
17
Maintainers
Readme
egg-mongoose-mock
Egg's mongoose plugin for unit testing.
Install
$ npm i egg-mongoose-mock --save-dev
Configuration
Change {app_root}/config/plugin.unittest.js
to enable egg-mongoose-mock
plugin:
exports.mongoose = {
enable: false,
package: 'egg-mongoose',
};
exports.mongooseMock = {
enable: true,
package: 'egg-mongoose-mock',
};
Simple connection
Config
// {app_root}/config/config.unittest.js
exports.mongoose = {
client: {
plugins: []
}
};
exports.mongooseMock = {
options: {
autoReconnect: true,
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
useUnifiedTopology: true,
},
};
Example
// {app_root}/app/model/user.js
module.exports = app => {
const mongoose = app.mongoose;
const Schema = mongoose.Schema;
const UserSchema = new Schema({
userName: { type: String },
password: { type: String },
});
return mongoose.model('User', UserSchema);
}
// {app_root}/app/controller/user.js
exports.index = function* (ctx) {
ctx.body = yield ctx.model.User.find({});
}
Default config
see config/config.default.js for more detail.
Questions & Suggestions
Please open an issue here.
Contribution
If you are a contributor, follow CONTRIBUTING.